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

              
                <div class="container text-center">
  <div class="options">
    <h1>Simon</h1>
    <a class="btn btn-primary btnOff" id="onSwitch">Start</a>
    <a class="btn btn-primary" id="resetSwitch">Reset</a>
    <a class="btn btn-primary" id="strictMode">Strict mode</a>
    <a class="btn btn-primary" id="turnNumber">Turn: 1</a>
  </div>
  <a class="btn but blue" id="blue"></a>
  <a class="btn but red" id="red"></a>
  <a class="btn but yellow" id="yellow"></a>
  <a class="btn but green" id="green"></a>
</div>
              
            
!

CSS

              
                body {
  background-color: #333;
}

.btnOn{
  border-color:#fff;
  background-color:#fff;
}

#onSwitch, #strictMode, #resetSwitch, #offSwitch, #turnNumber{
  font-size: 2.0em;
}
h1 {
  color: #fff;
}
.options {
  margin-top: 15px;
}

.container {
  margin-left: auto;
  margin-right: auto;
}

.but {
  margin-left: 10px;
  margin-right: 10px;
  margin-top: 20px;
  width: 150px;
  height: 150px;
}

.blue {
  background-color: #004cff;
  border-color: #004cff;
}
.blueActive{  
  background-color: #3873ff;
  border-color: #3873ff;
}

.red {
  background-color: #FF0000;
  border-color: #FF0000;
}
.redActive{  
  background-color: #ff4747;
  border-color: #ff4747;
}
.yellow {
  background-color: #FFFF00;
  border-color: #FFFF00;
}
.yellowActive{ 
  background-color: #ffff75;
  border-color: #ffff75;
}
.green {
  background-color: #00FF00;
  border-color: #00FF00;
}
.greenActive{  
  background-color: #8eff8e;
  border-color: #8eff8e;
}
              
            
!

JS

              
                $(document).ready(function() {
  var test = 0;
  var playerTurn = false;
  var playerSeq = [];
  var simonSeq = [];
  var turnCheck = [];
  var simonTurn = [];
  var turn = 1;
  var strict = false;
  var maxLevel = 20;
  var i = 0;
  var cl = 0;
  var on = 0;
  var audioBlue = new Audio(
    "https://s3.amazonaws.com/freecodecamp/simonSound1.mp3"
  );
  var audioRed = new Audio(
    "https://s3.amazonaws.com/freecodecamp/simonSound2.mp3"
  );
  var audioYellow = new Audio(
    "https://s3.amazonaws.com/freecodecamp/simonSound3.mp3"
  );
  var audioGreen = new Audio(
    "https://s3.amazonaws.com/freecodecamp/simonSound4.mp3"
  );

  function checkCorrect() {
    if (simonTurn.length > playerSeq.length){
        console.log(simonSeq[cl]);
      console.log(playerSeq[cl]);
      if (simonSeq[cl] != playerSeq[cl]){
        if (strict === true){
          simonSeq = [];
          playerSeq = [];
          turnCheck = [];
          simonTurn = [];
          turn = 1;
          i = 0;
          strict = false;
          $("#strictMode").removeClass("btnOn");
          $("#onSwitch").removeClass("btnOn");
          $("#onSwitch").text("Start");
          $("#turnNumber").text("Turn: 1");
          $("#strictMode").addClass("btn btn-primary");
          $("#strictMode").text("Strict Mode");
          
        } else{
        setTimeout(function(){
      $("#turnNumber").text("Turn: "+turn + " Oops! Try again!");
          playerSeq = [];
          turnCheck = [];
          simonTurn = [];
          i = 0;
          simonDoes();
},500);
        }
      
        }cl++;
    } else if (simonTurn.length == playerSeq.length) {
      cl = 0;
      if (simonTurn.join() == playerSeq.join()) {
        if (turn == 20) {
          setTimeout(function(){
          alert("Congratulations! You win!");
          simonSeq = [];
          playerSeq = [];
          turnCheck = [];
          simonTurn = [];
          turn = 1;
          $("#turnNumber").text("Turn: 1");
            });
        } else {
          playerSeq = [];
          simonTurn = [];
          setTimeout(function() {
            turn++;
            i = 0;
            $("#turnNumber").text("Turn: " + turn);
            
            simonDoes();
          }, 1500);
        }
      } 
      
      else {
        if (strict === true) {
          console.log('resetted');
          simonSeq = [];
          playerSeq = [];
          turnCheck = [];
          simonTurn = [];
          turn = 1;
          i = 0;
          strict = false;
          $("#strictMode").removeClass("btnOn");
          $("#onSwitch").removeClass("btnOn");
          $("#onSwitch").text("Start");
          $("#turnNumber").text("Turn: 1");
          $("#strictMode").addClass("btn btn-primary");
          $("#strictMode").text("Strict Mode");
        }
      
      else {
        setTimeout(function() {
          $("#turnNumber").text("Turn: "+turn + " Oops! Try again!");
          playerSeq = [];
          turnCheck = [];
          simonTurn = [];
          i = 0;
          simonDoes();
        }, 750);
      }
      }
    }
    
      
      }
    
  

  function simonDoes() {
    
    var myInter = setInterval(function() {
      playerTurn = false;
      if (simonSeq[i] == 1) {
        $("#blue").addClass("blueActive");
        audioBlue.play();
        simonTurn.push(1);
        setTimeout(function() {
          $("#blue").removeClass("blueActive");
        }, 250);
      } else if (simonSeq[i] == 2) {
        $("#red").addClass("redActive");
        audioRed.play();
        simonTurn.push(2);
        setTimeout(function() {
          $("#red").removeClass("redActive");
        }, 250);
      } else if (simonSeq[i] == 3) {
        $("#yellow").addClass("yellowActive");
        audioYellow.play();
        simonTurn.push(3);
        setTimeout(function() {
          $("#yellow").removeClass("yellowActive");
        }, 250);
      } else if (simonSeq[i] == 4) {
        $("#green").addClass("greenActive");
        audioGreen.play();
        simonTurn.push(4);
        setTimeout(function() {
          $("#green").removeClass("greenActive");
        }, 250);
      }
      
      i++;
      if (i >= turn) {
        clearInterval(myInter);
        playerTurn = true;
      }
    }, 750);
      
  }

  $("#onSwitch").click(function() {
    if ($("#onSwitch").hasClass("btnOn")) {
      $("#onSwitch").addClass("btnOff");
      $("#onSwitch").removeClass("btnOn");
      $("#onSwitch").text("Start");
      $("#strictMode").addClass("btn btn-primary");
      $("#strictMode").text("Strict Mode");
      reload.location();
      turn = 0;
      $("#turnNumber").text("Turn: " + (turn + 1));
    } else if ($("#onSwitch").hasClass("btnOff")) {
      $("#onSwitch").addClass("btnOn");
      $("#onSwitch").removeClass("btnOff");
      $("#onSwitch").text("Stop");
    }
    $("#strictMode").removeClass("btn btn-primary");
    $("#strictMode").text("");
    if (simonSeq.length === 0) {
      for (var k = 0; k < maxLevel; k++) {
        simonSeq.push(Math.floor(Math.random() * 4 + 1));
      }
      console.log(simonSeq);
    }
    
    simonDoes();
  });
  $("#blue").click(function() {
    if (!playerTurn) return;
      $("#blue").addClass("blueActive");
      audioBlue.play();
      playerSeq.push(1);

      setTimeout(function() {
        $("#blue").removeClass("blueActive");
      }, 250);
      checkCorrect();
    });
    $("#red").click(function() {
      if (!playerTurn) return;
      $("#red").addClass("redActive");
      audioRed.play();
      playerSeq.push(2);
      setTimeout(function() {
        $("#red").removeClass("redActive");
      }, 250);
      checkCorrect();
    });
    $("#yellow").click(function() {
      if (!playerTurn) return;
      $("#yellow").addClass("yellowActive");
      audioYellow.play();
      playerSeq.push(3);
      setTimeout(function() {
        $("#yellow").removeClass("yellowActive");
      }, 250);
      checkCorrect();
    });
    $("#green").click(function() {
      if (!playerTurn) return;
      $("#green").addClass("greenActive");
      audioGreen.play();
      playerSeq.push(4);
      setTimeout(function() {
        $("#green").removeClass("greenActive");
      }, 250);
      checkCorrect();
    });

    
    
  $("#resetSwitch").click(function() {
    test = 1;
    turn = 1;
    simonSeq = [];
    playerSeq = [];
    turnCheck = [];
    simonTurn = [];
    i = 0;
    
    $("#strictMode").removeClass("btnOn");
    $("#onSwitch").removeClass("btnOn");
    $("#onSwitch").text("Start");
    $("#turnNumber").text("Turn: 1");
    $("#strictMode").addClass("btn btn-primary");
    $("#strictMode").text("Strict Mode");
    location.reload();
  });


  $("#strictMode").click(function() {
    turn = 1;
    simonSeq = [];
    playerSeq = [];
    turnCheck = [];
    simonTurn = [];
    i = 0;
    strict = true;
    $("#strictMode").addClass("btnOn");
  });
});

/*  function startSequence(turn, simonSeq) {
    console.log(simonSeq);
    for (var j = 0; j < turn - 1; j++) {
      console.log(simonSeq[j]);
      if (simonSeq[j] === 1) {
        console.log("blue");
      } else if (simonSeq[j] === 2) {
        console.log("red");
      } else if (simonSeq[j] === 3) {
        console.log("yellow");
      } else if (simonSeq[j] === 4) {
        console.log("green");
      }
    }
  }*/

/*
   

  function startSequence(){
    i = 0;
  $('#turnNumber').text("Turn: "+ turn);
   simonSeq.push((Math.floor(Math.random() * 4));
    var gameWork = setInterval(function() {
      var number = simonSeq[i];
     console.log(number);
      if (number === 0){
        $(".blue").addClass(".blueActive");
      }
      else if (number === 1){
        $(".red").addClass(".redActive");}
      else if (number === 2{
        $(".yellow").addClass(".yellowActive");}
      else if (number === 3){
        $(".green").addClass(".greenActive");}
      setTimeout (function(){
        $(".blue").removeClass(".blueActive");
        $(".red").removeClass(".redActive");
        $(".yellow").removeClass(".yellowActive");
        $(".green").removeClass(".greenActive");
      }, 500);
    if (i == simonSeq.length){
    clearInterval(setInterval);

    }, 1500);
    
  });

    
    */

/*var blue = "blue";
var red = "red";
var yellow = "yellow";
var green = "green";

var simon = {
  sendColor: function(color) {
    if (simon.sequence.length === 0) {
      simon.nextSequence();
      console.log(simon.sequence);
    } else {
      if (color === simon.sequence[simon.step]) {
        if (simon.step === simon.sequence.length - 1) {
          console.log("seq comp");
          simon.step = 0;
          simon.nextSequence();
        } else {
          simon.step++;
        }
      } else {
        alert("Wrong!");
        simon.sequence = [];
        simon.step = 0;
      }
    }
  },

  sequence: [],
  round: 0,
  nextSequence: function() {
    
    simon.sequence.push(nColor);
  }
};

$(document).ready(function() {
  $("#blue").click(function() {
    simon.sendColor(blue);
  });
  $("#red").click(function() {
    simon.sendColor(red);
  });
  $("#yellow").click(function() {
    simon.sendColor(yellow);
  });
  $("#green").click(function() {
    simon.sendColor(green);
  });
});
*/

              
            
!
999px

Console