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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div class = "coverme" >
  <button class = "b1" id = "1"></button>
  <button class = "b2" id = "2"></button> 
</div>

<div class="coverme">
  <button class="bswitch" id="btn-swtch">Power</button>
  <section class="output">--</section>
  <button class="bswitch" id="btn-strict">Strict </button>
</div>

<div class="coverme">
  <button class = "b3" id = "3"> </button>
  <button  id = "4"></button>
</div> 

              
            
!

CSS

              
                button {
  background: blue;
  color: white;
  cursor: pointer;
  padding: 23.5%;
  z-index: 10;
  margin: 1px;
  }

.b1{
  background: #E74C3C;
}
.b1:hover{
    background:#F5B7B1
}
.b1:active{
  background:#C0392B;
}
.b2{
  background:#7D3C98;
}
.b2:hover{
  background:#bb8fce;
}
.b2:active{
  background:#6c3483;
}
.b3{
  background: #f4d03f;
}
.b3:hover{
  background: #f9e79f;
}
.b3:active{
  background: #f5b041;
}
button:hover{
  background: #Aed6f1;
}
button:active{
  background:#2471a3;
}

.coverme
{ 
  text-align: center;
  position: relative;
  width: 100%;
  max-width: 300px; 
  background-color: white;
  margin: 0 auto;
  border-style: solid;
  border-width: 5px;
}
.bswitch{
  padding: 1px 50px 1px 50px;
  margin: 5px;
  background:black;
}
.bswitch:hover{
   background:white;
   color: blue;
 }
.output{
  border-style: solid;
  width: 10%;
  margin: auto;
}
.lightup{
  background: white;
}
              
            
!

JS

              
                $(document).ready(function(){
  var audio1 = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3');
  var audio2 = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound2.mp3');
  var audio3 = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound3.mp3');
  var audio4 = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound4.mp3');
  var arraudio =["",audio1,audio2,audio3,audio4];
  var gamingMatrix = [];
  var matchMatrix = [];
  var turn = 0;
  var gameSwitch = false;
  var strictmode = false;
  var cycle = 0;
  
  console.log(arraudio[1]);
  
  function alloff(){
    document.getElementById("1").style.visibility ='hidden';
    document.getElementById("2").style.visibility ='hidden';
    document.getElementById("3").style.visibility ='hidden';
    document.getElementById("4").style.visibility ='hidden';
  }
  
  function allon(){
    document.getElementById("1").style.visibility ='visible';
    document.getElementById("2").style.visibility ='visible';
    document.getElementById("3").style.visibility ='visible';
    document.getElementById("4").style.visibility ='visible';
  }
  
  function clickyme(input){
    return(document.getElementById(input).click());
    }
  
  function offlight(input){
    $('#'+input).removeClass('lightup');
  }
  
  function lighters(input,input2){
    $('#'+ input).addClass('lightup');
    //input2.play();
    arraudio[input2].play();
    setTimeout(function(){offlight(input);},400);
  }
  
  function resetter(){
    turn = 0;
    cycle=0;
    alloff();
    gameSwitch = false;
    strictmode = false;
     $("#btn-strict").css("background","black");
    gamingMatrix =[];
    matchMatrix=[];
    $('.output').text("--");
   } 
  
  function thegame(input){
    var current = matchMatrix[turn]; 
    var currentStringTurn = current.toString(); 
    if (turn === 0){
      setTimeout(function(){
      lighters(currentStringTurn, current);}, 1000);
      turn+=1; 
      $('.output').text(turn);
      console.log("Returning the value of turn to be "+turn);
      return(turn);
    }
    else if(input != matchMatrix[cycle]){
      alert('Wrong! The value should be ' + matchMatrix[cycle] + " with the cycle of "+ cycle + " in turn of " + turn);
      $('.output').text("XX");
      resetter();//This is strict mode, will need to add another if statment to include non-strict mode
      return;
    }
    else if(input == matchMatrix[cycle]){
        console.log("The input matched the current " + matchMatrix[cycle]);
        cycle+=1; console.log("The cycle is now "+ cycle + " with turn of "+ turn);
        if(cycle == turn){
          var i = 0;
        function showme(){
          setTimeout(function(){
            lighters(matchMatrix[i].toString(),matchMatrix[i]);
            console.log(i +" lighters should light up now");
              i++;
              if(i < turn){
                showme();
              }
          } ,800); 
        }
          showme();
          cycle = 0;
          turn +=1; 
          $('.output').text(turn);
          console.log("Returning the cycle value of "+cycle+" with turn of "+turn);
          return(cycle,turn);
        } 
        else{
          console.log("Still on same turn = "+ turn + " with the cycle of " + cycle);
          return(turn,cycle);
        }
        
      }
      
    }

  
  
  if(!gameSwitch){alloff();}
    else{allon();
      }
  
  
  console.log("Initalized");
  

  //Setting up the Event Listener for the game
  
$(document).on('click','button', function(){

    if(this.id =="btn-swtch"){
      if (gameSwitch){
        $("#btn-swtch").css("background","black");
        gameSwitch = false; 
        console.log("game off!"); 
        resetter();
        return(gameSwitch);
      }
     else if (!gameSwitch){ 
      $('#btn-swtch').css("background", 'red');
      gameSwitch = true; 
      console.log("game on!");  
        //creating 20 randomized sequence for the game 
      for(i=0; i<20; i++){
        matchMatrix[i] = Math.floor(Math.random()*4) + 1;
      }
      console.log("The randomized sequence is created: " + matchMatrix);
      allon();
      thegame();
      return(gameSwitch);
      }
    }
if(this.id =="btn-strict"){
      if (strictmode){
        $("#btn-strict").css("background","black");
        strictmode = false; 
        console.log("strict mode is off!"); 
        return(strictmode);
      }
     else if (!strictmode){ 
      $('#btn-strict').css("background", 'red');
      strictmode = true; 
      console.log("The strict mode is on!");  
      return(strictmode);
      }
    }

     else if(this.id == "1"){
        lighters(this.id,1); 
      // setTimeout(function(){lighters(this.id,audio1);},2000); 
       //setTimeout(lighters.bind(null,this.id,audio1),2000);  
       gamingMatrix.push(1); 
       console.log(gamingMatrix);
        console.log(this.id);
       thegame(this.id);
      }
               
     else if(this.id == "2"){audio2.play(); gamingMatrix.push(2); console.log(gamingMatrix);thegame(this.id);}
     else if(this.id == "3"){audio3.play(); gamingMatrix.push(3); console.log(gamingMatrix);thegame(this.id);}
     else if(this.id == "4"){audio4.play(); gamingMatrix.push(4); console.log(gamingMatrix);thegame(this.id);}
     console.log("gamingMatrix is "+ gamingMatrix);
  });
});

              
            
!
999px

Console