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

              
                

 <embed src="https://s3.amazonaws.com/freecodecamp/simonSound1.mp3" autostart="false" width="0" height="0" id="noise1"
enablejavascript="true">

  <embed src="https://s3.amazonaws.com/freecodecamp/simonSound2.mp3" autostart="false" width="0" height="0" id="noise2"
enablejavascript="true">

  <embed src="https://s3.amazonaws.com/freecodecamp/simonSound3.mp3" autostart="false" width="0" height="0" id="noise3"
enablejavascript="true">

  <embed src="https://s3.amazonaws.com/freecodecamp/simonSound4.mp3" autostart="false" width="0" height="0" id="noise4"
enablejavascript="true">




<div id="count" style="color:white;"></div>
<div id="circle">
   <div id="box">
  <div class="colors" id="red"></div>
  <div class="colors" id="green"></div>
  </div>
  
  <div  id="circle_sm">
    <h1>Start Game</h1>
  <button id="start"> start</button>
<button id="restart" > restart</button>
<button id="strict">strict mode</button>

  </div>
 
  
  <div id="box1">
  <div class="colors" id="yellow"></div>
  <div class="colors" id="blue"></div>
  </div>



</div>
              
            
!

CSS

              
                body{
  background-image:url('https://snap-photos.s3.amazonaws.com/img-thumbs/280h/A8DQ8W3OCI.jpg');
  background-repeat:no-repeat;
  background-attachment:fixed;
  position:relative;
  background-size:cover;
  background-position:center;
  
}
#circle{
  border:1px solid black;
  height:600px;
  width:60%;
  border-radius:100%;
  text-align:center;
  margin:auto;
  padding:20% 10% 10% 15%;
  background-color:grey;
  
  
}

#circle_sm{
  
   border:1px solid black;
  height:40%;
  width:40%;
  border-radius:100%;
  margin:auto;
  padding:5%;
  background-color:white;
}

#red{
  height:200px;
 width:30%;
  border:1px solid red;
  background-color:red;
  float:left;
 
  
}

#blue{
  height:200px;
  width:30%;
  border:1px solid blue;
  margin-left:30%;
  background-color:blue;
  float:right;
  
}
#yellow{
  height:200px;
  width:30%;
  border:1px solid yellow;
  background-color:yellow;
  float:left;
}
#green{
  height:200px;
  width:30%;
  border:1px solid green;
  background-color:green;
  float:right;
}
.colors{
 display:inline-block;
 border-radius:100%;
  
}


.fil{
  filter: opacity(.2);
  
}
button{
  display:block;
  margin:auto;
  
}



              
            
!

JS

              
                 
$(document).ready(function(){
  /*Ui setup*/
  var audio;
  var step=1;
  var machine=[];
 var human=[];
  var counter=0;
  var cols=document.getElementsByClassName("colors");
  
  $("#count").html(step);
  
  
  /*functions*/
    //sound func
  
  
   //eval func
  /*problem: evals each element one at a time instead of the entire array. will win if one is correct.*/
        function win(){
      var winSom=setInterval(function(){
        machine.forEach(function(mac){
  human.forEach(function(hum){
    if(mac===hum &&machine.length===human.length){
      console.log("yay!!!!",machine, human);
      step++;
       $("#count").html(step);
      machine=[];
      human=[];
       $("h1").html("Next Round! Press Start");
      $(".colors").removeClass("fil");
       audio=new Audio('https://s3.amazonaws.com/freecodecamp/simonSound2.mp3');
        audio.play();
      clearInterval(win);
      
    }else if(mac !==hum && $("#strict").data('clicked')===true){
      
      step=2;
      machine=[];
      human=[];
      console.log("restart", machine, human);
     
      $("h1").html("Game Over");
      $(".colors").removeClass("fil");
       audio=new Audio('https://s3.amazonaws.com/freecodecamp/simonSound4.mp3');
        audio.play();
      clearInterval(win);
    } else{
      console.log("nooo.....",machine, human);
      //redo the machine at it's current length.
      for(var k=0; k<machine.length;k++){
        $(machine[k]).addClass('fil');
        audio=new Audio('https://s3.amazonaws.com/freecodecamp/simonSound4.mp3');
        audio.play();
      }
      $("h1").html("Try Again. Press Start");
      
      $(".colors").removeClass("fil");
      clearInterval(win);
    }
      
    
    });
  
});
   
      },5000);

}
  

  
   //strict btn func
  $("#strict").on('click', function(){
    $(this).data('clicked', true);
    
  });
  
  //restart btn func
  $("#restart").on('click',function(){
    step=2;
    machine=[];
    human=[];
     $("#count").html(step);
    $(".colors").removeClass("fil");
    
    
  });
  
 
  
   //human choice func

 $(".colors").on('click',function(e){
  var $this=$(this);
 var attHum=$this.attr("id");
  human.push(attHum);
    
  audio=new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3');
        audio.play();
   
  e.preventDefault();
  
  
});
  //end of human choice
  
  
  
  
  $("#start").on('click', function(){
    //main game func
     
   
        
          //machine choice(s) func
           function mMove(stop){
              $(".colors").removeClass('fil');
     var i=0;
       var set=setInterval(function(){
         
          var random=Math.floor(Math.random()*cols.length);
    
      var col=$(".colors").eq(random);
      var attCol=col.attr("id");
     machine.push(attCol);
      col.addClass('fil');
         setTimeout(function(){
           col.removeClass('fil');
           
         },800);
         
         if(i===stop){
           clearInterval(set);
           
         }
         
         i++; 
         
         //end of machine move
          audio=new Audio('https://s3.amazonaws.com/freecodecamp/simonSound3.mp3');
        audio.play();
         //eval func call.         
  win();
              
           },1000);
             
       
    }
     mMove(step);
          //end of machine func
    
    
          //test if game is finished
        if(step===20){
          clearInterval(gameMove);
         $("h1").html("You've Won");
          $("#start").unbind();
          $("#strict").unbind();
          step=2;
          $("#count").html(step);
          machine=[];
          human=[];
          
        }  
                  
          
        
         
    //end of game function
           
  });
 //end of click
 

  

});


              
            
!
999px

Console