Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <link href="https://fonts.googleapis.com/css?family=Anton" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Orbitron" rel="stylesheet">
<audio id="audio1" src="https://s3.amazonaws.com/freecodecamp/simonSound1.mp3" autostart="false"></audio>
<audio id="audio2" src="https://s3.amazonaws.com/freecodecamp/simonSound2.mp3" autostart="false"></audio>
<audio id="audio3" src="https://s3.amazonaws.com/freecodecamp/simonSound3.mp3" autostart="false"></audio>
<audio id="audio4" src="https://s3.amazonaws.com/freecodecamp/simonSound4.mp3" autostart="false"></audio>
<body> 
  <div class="grey-box">
    <div class="main">
    <div class=" quarter quarter1" id="quarter1"></div>
    <div class=" quarter quarter2" id="quarter2"></div>
    <div class=" quarter quarter3" id="quarter3"></div>
    <div class=" quarter quarter4" id="quarter4"></div>
    <div class="cutout" style="font-size: 25px;">Simon
      <div style="display: inline-block;">
      <div class="count-box">--
        </div>
          <div class="start-button" style="float: center;">
          </div>
        <p style="font-size: 10px; float: left; margin-top: 30px; margin-left: -20px;">Start</p>
        <div class="strict-button" id="strict">
          </div>
        <p style="font-size: 10px; float: left; margin-top: 30px; margin-left: -20px; display: block;">Strict</p>
        </div>
      <div style="font-size: 20px; display: inlineblock; vertical-align: text-top; margin-top: -10px;">
        <span class="align-top">OFF </span>
    <label class="switch">
      <input type="checkbox">
      <div class="slider">
        </div>
    </label>  
        <span class="align-top">On </span>
        </div>
        </div>
      </div>
</div>
    
              
            
!

CSS

              
                body {
    background-image: url("https://www.toptal.com/designers/subtlepatterns/patterns/skulls.png");
    background-repeat: repeat;
    font-family: 'Anton', sans-serif;
}

.grey-box{
  width: 425px;
  height: 425px;
  border-radius: 50%;
  margin: auto;
  margin-top: 50px;
  padding: 12.5px;
  background-color: #5a5b5b;
}
.main {
  position: relative;
  width: 400px;
  height: 400px;
  margin: 0 auto;
}
.quarter {
  position: absolute;
  width: 50%;
  height: 50%;
  transition: background-color 0.2s ease-in-out;
  border: 5px solid #5a5b5b;
  
}
.quarter:hover {
  cursor: pointer;
}
.start-button:hover {
  cursor: pointer;
}
.strict-button:hover {
  cursor: pointer;
}
.quarter:active {
  filter: brightness(150%); !important;
}
.active {
  filter: brightness(150%); !important;
}
.quarter1 {
  top: 0;
  left: 0;
  background-color: #b20000;
  border-radius: 100% 0 0 0;
}
.quarter2 {
  top: 0;
  right: 0;
  background-color: #004ead;
  border-radius: 0 100% 0 0;
}
.quarter3 {
  bottom: 0;
  left: 0;
  background-color: orange;
  border-radius: 0 0 0 100%;
}
.quarter4 {
  bottom: 0;
  right: 0;
  background-color: green;
  border-radius: 0 0 100% 0;
}
.cutout {
  width: 50%;
  height: 50%;
  background-color: white;
  text-align: center;
  padding: 10px;
  position: absolute;
  top: 25%;
  left: 25%;
  border-radius: 50%;
  border: 10px solid #5a5b5b;
  
}
.count-box{
  width: 50px;
  height: 40px;
  border-radius:10%;
  background-color: #770e07;
  color: #Ff2111;
  font-family: Orbitron, sans-serif;
  border-style: solid;
  border-color:#2b2929;
  margin-top:10px;
  float: left;
  
}
.start-light{
  width: 5px;
  height: 5px;
  border-radius:50%;
  background-color: black;
  color: black;
  font-family:  'Anton', sans-serif;
  border-style: solid;
  border-color:#2b2929;
  margin-top:10px;
  margin-left: 20px;
  float: left;
}
.start-button{
  width: 20px;
  height: 20px;
  border-radius:50%;
  background-color: #Ff2111;
  color: black;
  font-family:  'Anton', sans-serif;
  border-style: solid;
  border-color:#2b2929;
  margin-top:10px;
  margin-left: 20px;
  float: left;
}
.strict-button{
   width: 20px;
  height: 20px;
  border-radius:50%;
  background-color: black;
  color: black;
  font-family:  'Anton', sans-serif;
  border-style: solid;
  border-color:#5a5b5b;
  margin-top:10px;
  margin-left: 20px;
  float: left;
}

.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switch input {display:none;}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .slider {
  background-color: #2196F3;
}

input:focus + .slider {
  box-shadow: 0 0 1px #2196F3;
}

input:checked + .slider:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}
              
            
!

JS

              
                var gameOn = false;
var strict = false;
var count = 0;
var colorArr = [];
var playerArr = [];
var funcCount = 0;
var allowMove = false;

function checkArrs(){ 
  for(var i = 0; i< playerArr.length; i++){
    if(playerArr[i] != colorArr[i]){
      var audio = $("#audio1")[0];
      audio.play();
      var audio = $("#audio2")[0];
      audio.play();
      var audio = $("#audio3")[0];
      audio.play();
      var audio = $("#audio4")[0];
      audio.play();
      $(".quarter").addClass('active');
      setTimeout(function(){ $(".quarter").removeClass('active') }, 500);
      return false;
    }
  }
  return true;
}
// fadeOut activates and deactivates buttons
function fadeOut(str, len){
  $("#"+str).addClass('active');
  var audio = $("#audio"+str.substr(str.length-1))[0];
  audio.play();
  setTimeout(function(){ $("#"+str).removeClass('active') }, 500);
  //stops player from pressing buttons before simon is finished
  if(len+1 == colorArr.length)
    allowMove = true;
};
//gameGo adds counts and calls fadeOut to show the player the pattern
function gameGo(moveOn){
  allowMove = false;
  var rand = parseInt((Math.random() * 4) + 1);
  if(gameOn){  
    if(moveOn){
      count++;
      $('.count-box').html(count);
      colorArr.push("quarter" + rand); 
    }
    for(var i = 0; i < colorArr.length; i++){
      console.log(colorArr[i] +', ' + i);
      playerArr = [];
      (function(i) {
       setTimeout(function(){fadeOut(colorArr[i], i);}, (1000 * i));
   })(i);
      }
   var y = colorArr.length
    (function(y) {
        setTimeout(function(){allowMove=true}, (1000 * y));
   })(i);
  }
};
$(document).ready(function(){
  $('.slider').on('click', function(){
    if(gameOn){
      gameOn = false;
      $('.count-box').html("--");
      count = 1;
      colorArr = [];
      playerArr = [];
    }else
      gameOn = true;
  });
  $('.start-button').on('click', function(){
    if(gameOn){
      colorArr = [];
      playerArr = [];
      count = 0;
      $('.count-box').html(count);
      gameGo(true, true);
    }
  });
  $('#strict').on('click', function(){
    if(strict){
      strict = false;
      $("#strict").css("background-color", "black");
    }else{
      strict = true;
      $("#strict").css("background-color", "yellow");
    }
  });
  
  $('#quarter1').on('click', function(){
    if(allowMove){
     var audio = $("#audio1")[0];
     audio.play();
     playerArr.push(this.id);
     console.log(checkArrs());
     console.log(playerArr);
     if(checkArrs()){
       if( playerArr.length == count)
         setTimeout(function(){gameGo(true)}, 1000);
       console.log("hello");
     }else if(strict){
       colorArr = [];
       count = 0;
       setTimeout(function(){gameGo(true)}, 1000);
     } else 
       setTimeout(function(){gameGo(false)}, 1000); 
    }
   });
  $('#quarter2').on('click', function(){
    if(allowMove){
     var audio = $("#audio2")[0];
     audio.play();
     playerArr.push(this.id);
     console.log(checkArrs());
     console.log(playerArr);
     if(checkArrs()){
       if( playerArr.length == count)
         setTimeout(function(){gameGo(true)}, 1000);
       console.log("hello");
     }else if(strict){
       colorArr = [];
       count = 0;
       setTimeout(function(){gameGo(true)}, 1000);
     }else
       setTimeout(function(){gameGo(false)}, 1000);
    }
   });
  $('#quarter3').on('click', function(){
    if(allowMove){
     var audio = $("#audio3")[0];
     audio.play();
     playerArr.push(this.id);
     console.log(checkArrs());
     console.log(playerArr);
     if(checkArrs()){
       if( playerArr.length == count)
        setTimeout(function(){gameGo(true)}, 1000);
       console.log("hello");
     }else if(strict){
       colorArr = [];
       count = 0;
       setTimeout(function(){gameGo(true)}, 1000);
     }else
       setTimeout(function(){gameGo(false)}, 1000);
    }
   });
  $('#quarter4').on('click', function(){
    if(allowMove){
     var audio = $("#audio4")[0];
     audio.play();
     playerArr.push(this.id);
     console.log(checkArrs());
     console.log(playerArr);
     if(checkArrs()){
       if(playerArr.length == count)
         setTimeout(function(){gameGo(true)}, 1000);
       console.log("hello");
     }else if(strict){
       colorArr = [];
       count = 0;
       setTimeout(function(){gameGo(true)}, 1000);
     } else
       setTimeout(function(){gameGo(false)}, 1000);
    }
   });
  
});
              
            
!
999px

Console