Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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=Bungee" rel="stylesheet">

<div class="container-fluid">
<div class="simon">
  <div class="green quad" id="simonBtn1"> 
   
  </div>
  
  <div class="red quad" id="simonBtn2">
  </div>
  
  <div class="yellow quad" id="simonBtn3">
  </div>
  
  <div class="blue quad" id="simonBtn4">
  </div>
  
 <div class="inner-circle">
   <div class="row" id="title">
     <h2>Simon Game</h2>
   </div>
   <div class="row">
      <div id="strictCircle"></div>
   </div>
   
    <div class="row displayBtn">
  <button class="btn btn-primary btn3" id="countBtn"><h3 id="countValue">00</h3>
       </button>
      <div class="smallcircle" id="startBtn"></div>
      <div class="smallcircle" id="strictBtn"></div>
  
   </div>
   
   
    <div class="row buttonTitle">
      <h4>Count</h4>
      <h4>Start</h4>
      <h4>Strict</h4>
  
   </div>
   
   <div class="row displayBtn">
  
      <div class="smallcircle" id="restartBtn"></div>
     
   </div>
   
   <div class="row restartBtn">
     <h5>Restart</h5>
     </div>
   
   
  </div>

</div>




    
     <audio id="sound1" src="https://s3.amazonaws.com/freecodecamp/simonSound1.mp3" preload="auto"></audio>
    
    <audio id="sound2" src="https://s3.amazonaws.com/freecodecamp/simonSound2.mp3" preload="auto"></audio>
    
    <audio id="sound3" src="https://s3.amazonaws.com/freecodecamp/simonSound3.mp3" preload="auto"></audio>
    
    <audio id="sound4" src="https://s3.amazonaws.com/freecodecamp/simonSound4.mp3" preload="auto"></audio>
  
    <footer class="page-footer">
    Project by <a href="https://codablejoy.com/" >CodableJoy</a>
    </footer>
    
  </div>


              
            
!

CSS

              
                .simon{
  width: 600px;
  height:600px;
  background: white;
  margin: auto;
  border-radius: 50%;
  margin-top: 50px;
 border-style:solid;
  border-width: 5px;
 
  
 /* display: flex;
  flex-grow: 1;
  flex-direction: row;*/
}

.inner-circle{
  
  position: absolute;
  background:white;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  margin-top: 150px;
  margin-left: 145px;
  border-style: solid;
  border-width: 10px;
  vertical-align: middle;
  text-align:center;
}

#title{
  vertical-align: middle;
  display: inline-block;
  padding-top: 30px;
}

.displayBtn{
  margin-top: 20px;
  margin-left: 20px;
  vertical-align: middle;
}

#countBtn{
  background-color:black;
  color: red;
  padding-top: 15px;
  width: 70px;
   
}

#countValue{
  padding-top: 3px;
}

.restartBtn{
  margin-left:112px;
  padding-top: 5px;
}

/*h5{
  margin-top: -8px;
}*/

.smallcircle{
  height: 40px;
  width: 40px;
  border-style: solid;
  border-width: 7px;
  margin-left: 20px;
  border-radius: 50%;
  margin-top: 8px;
  margin-left: 35px;
  vertical-align: middle;
  box-shadow: 0px 3px grey;
}

#strictCircle{
  height: 15px;
  width: 15px;
  background:black;
  border-style: solid;
  border-width: 3px;
  margin-left: 20px;
  border-radius: 50%;
  margin-top: 8px;
  margin-bottom: -25px;
  margin-left: 227px;
  vertical-align: middle;
  /*box-shadow: 0px 3px grey;*/
}

.buttonTitle{
  padding: 10px;
  margin-left: 6px;
}

h3{
   font-size: 20px;
  font-family: 'Bungee', cursive;
}

h4{
  padding-top: 8px;
  padding-left: 18px;
  font-size: 17px;
  font-family: 'Bungee', cursive;
}

h2{
  font-family: 'Bungee', cursive;
  font-size: 28px;
}

h5{
  
  font-family: 'Bungee', cursive;
  font-size: 15px;
  
}

#startBtn{
  background-color: green;
}

#strictBtn{
  background-color: red;
}

#restartBtn{
  background-color: yellow;
  margin-top: -20px;
  margin-left: 105px;
  
}




.quad{
  width:50%;
  height:50%;
  background: black;
  float: left;
  border-style:solid;
  border-width: 5px;
 
   
}




.green{
  background:#228B22;
  border-top-left-radius: 100%;
  
  
}

.red{
  background:#B22222;
  border-top-right-radius: 100%;
}

.yellow{
  background: #FFD700;
  border-bottom-left-radius: 100%;
}

.blue{
  background: #4169E1;
  border-bottom-right-radius: 100%;
}

.page-footer{
  margin-top: 150px;
  font-size: 20px;
  text-align: center;
}

              
            
!

JS

              
                $(document).ready(function() {
  
  var count = 0;
  //buttons for machine to click
  var arrM =[];
  //buttons player clicked on
  var arrP=[];
  var allBtn = [1, 2, 3, 4];
  
  var btnID = 0;
  var checkResult;
  var btnM = 0;
  var strictMode = 0;
  var colorOrgnl1 = "#228B22";
  var colorOrgnl2 = "#B22222";
  var colorOrgnl3 = "#FFD700";
  var colorOrgnl4 = "#4169E1";
  var colorChgn1 = "#7CFC00";
  var colorChgn2 = "#FF0000";
  var colorChgn3 = "#FFFF00";
  var colorChgn4 = "#0000FF";
  var colorOrgnl="";
  var colorChgn="";
  var checkBtn = "True"; 
  
  function colorbyID(btnID){
    
     if(btnID==1){
        colorChgn = colorChgn1;
        colorOrgnl = colorOrgnl1;
      }
      
      else if(btnID== 2){
        colorChgn = colorChgn2;
        colorOrgnl = colorOrgnl2;
      }
      
      else if(btnID==3){
        colorChgn = colorChgn3;
        colorOrgnl = colorOrgnl3;
      }
      else {colorChgn = colorChgn4;
           colorOrgnl = colorOrgnl4;}
    
    
  }
  
  //function for increase the number of buttons played
  function increaseBtn(){
    
   var randomBtn = allBtn[Math.floor(Math.random() * allBtn.length)];
   arrM.push(randomBtn);
   //display the count of buttons with a delay
   // setTimeout(function(){
     // $('#countBtn').html("Count: " + arrM.length); 
   // }, 500);
   
   console.log('increaseBtn');
  }
  
    //function for machine to activate the buttons
 function machinePlay(){
   console.log('machinePlay');
   console.log(arrM);
   $('#countValue').html(arrM.length);  
for (var i = 0; i < arrM.length; i++)
{
  (function(index){
    
    setTimeout(function(){
     
      colorbyID(arrM[index]);
      $('#simonBtn'+ arrM[index]).css('background-color',colorChgn);  
       document.getElementById('sound' + arrM[index]).play();
      setTimeout(function(){
        $('#simonBtn'+ arrM[index]).css('background-color',colorOrgnl);
      }, 300);
    }, 2000+1000*index);
  }) (i);
  
};
 }
  //function to check whether player buttons match machine buttons
   function checkPlayer (){
     
    if(arrP.length == arrM.length) 
 { for(var i=0; i<arrP.length; i++){
    if(arrP[i]!=arrM[i]){
     checkBtn = "False";
    }
    else {checkBtn = "True";}
  }
     
     if(checkBtn == "False"&&strictMode == 0){
   $('#countValue').html("!!"); 
  
     setTimeout(function(){
    machinePlay();
    }, 1000); 
         
       arrP=[];
     }
  
  else if(checkBtn == "False"&&strictMode == 1){
     $('#countValue').html("!!"); 
    arrM = [];
    arrP = [];
   increaseBtn();
    setTimeout(function(){
    machinePlay();
    }, 1000); 
  }
  
  else if(checkBtn == "True" && arrP.length == 20){
     $('#countValue').html("You won"); 
    setTimeout(function(){
       arrM = [];
      arrP=[];
   increaseBtn();
    machinePlay();
    }, 2000)
    
  }
     else {
       increaseBtn();
       machinePlay();
       arrP=[];
     }}
     
     console.log(checkBtn);
   }

 
  
  //function to start the game
  $('#startBtn').click(function(){
   arrM = [];
   increaseBtn();
    machinePlay();
  });
  
   $('#strictBtn').click(function(){
     if(strictMode == 0){
       strictMode = 1; 
     $('#strictCircle').css("background", "red");
     }
     
    else if(strictMode == 1){
        strictMode = 0; 
     $('#strictCircle').css("background", "black");
     }
   
  });
  
   $('#restartBtn').click(function(){
     strictMode = 0; 
    $('#strictCircle').css("background", "black");
   arrM = [];
   arrP =[];
   increaseBtn();
     setTimeout(function(){
    machinePlay();
    }, 1000); 
  });
 
   function recordPlayer(btnID){
     arrP.push(btnID);
     colorbyID(btnID);
      $('#simonBtn' + btnID).css('background-color',colorChgn);
     document.getElementById('sound' + btnID).play();
      setTimeout(function(){
      $('#simonBtn' + btnID).css('background-color',colorOrgnl);
}, 300);
     checkPlayer();
     
   }
  
  $('#simonBtn1').click(function(){
      recordPlayer(1);
    });
  
  $('#simonBtn2').click(function(){
      recordPlayer(2);
    });
  
  $('#simonBtn3').click(function(){
      recordPlayer(3);
    });
  
  
  $('#simonBtn4').click(function(){
      recordPlayer(4);
    });
  
  
  
  //function to check whether player click correct or not
 
 });
              
            
!
999px

Console