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

              
                <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<div class="row">
  <div class="top text-center"><p>Simon</p><span id="stepCounter">0</span>
    <div><button id="resetGame" class="btn">reset</button></div>
    <div><button id="strictMode" class="btn">strict</button></div></div>
  <div class="pull-left">
    <div class="tlcornerPiece"> </div>
    <div class="blcornerPiece">
    </div>
  </div>
  <div class="">
    <div class="trcornerPiece"> </div>
    <div class="brcornerPiece">
    </div>
  </div>
</div>

<audio id="greenSound">
  <source src="https://s3.amazonaws.com/freecodecamp/simonSound1.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>
<audio id="redSound">
  <source src="https://s3.amazonaws.com/freecodecamp/simonSound2.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>
<audio id="yellowSound">
  <source src="https://s3.amazonaws.com/freecodecamp/simonSound3.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>
<audio id="blueSound">
  <source src="https://s3.amazonaws.com/freecodecamp/simonSound4.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>
              
            
!

CSS

              
                .row{
  margin: 55px;
}

.mainCircle{
  background-color: #222222;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  padding: 20px; 
}

.greenBtn{
  background-color: #22bb55;
  width: 558px;
  height: 558px;
  border-top-left-radius: 50%;
  border: 15px solid #333333;
}

.redBtn{
  background-color: #22bb55;
  width: 558px;
  height: 558px;
  border-top-left-radius: 50%;
  border: 15px solid #333333;
}

.yellowBtn{
  background-color: #AAAA00;
  border: 15px solid #333333;
  width: 600px;
  height: 600px;
  padding: 20px;
  top:-345px;
}

.tlcornerPiece{
  background-color: #2fa340;
  border-top-left-radius: 100%;
  border-left: 15px solid #333333;
  border-top: 15px solid #333333;
  border-right: 15px solid #333333;
  width: 265px;
  height: 265px;
  overflow: hidden;
  
}.trcornerPiece{
  border-top-right-radius: 100%;
  background-color: #aa2222;
  border-right: 15px solid #333333;
  border-top: 15px solid #333333;
  width: 265px;
  height: 265px;
  overflow: hidden;
}

.blcornerPiece{
  border-bottom-left-radius: 100%;
  border: 15px solid #333333;
  width: 265px;
  height: 280px;
  background-color: #AAAA00;
}
.brcornerPiece{
  border-bottom-right-radius: 100%;
  border-bottom: 15px solid #333333;
  border-right: 15px solid #333333;
  border-top: 15px solid #333333;
  width: 265px;
  height: 280px;
  background-color: #2222aa;
  position: absolute;
  left: 320px;
}

.top{
  border-radius:100%;
  width: 200px;
  height: 200px;
  background-color: #ffffff;
  position:absolute;
  left:212px;
  top: 225px;
  z-index: 1;
  border: 15px solid #333333;
  padding-top: 10px;
}

.flashYellow{
  background-color: #eef442 !important;
}
.flashRed{
  background-color: #f44242 !important;
}
.flashBlue{
  background-color: #2C75FF !important;
}
.flashGreen{
  background-color: #42f45c !important;
}

.btn {
  margin: 5px;
}
              
            
!

JS

              
                var currentStep = 0;
var playerStep = 0;
var stepArray = [];
var loopSteps = true;
var roundComplete = true;
var strictMode = false;

$("#resetGame").on("mouseup", function() {
  resetGame();
});
$("#strictMode").on("mouseup", function() {
  $("#strictMode").toggleClass("btn-danger");
  resetGame();
  if (strictMode){
    strictMode = false;
  } else {
    strictMode = true;
  }
});

$(".tlcornerPiece").on("mousedown", function() {
  $('#greenSound')[0].play();
  $(".tlcornerPiece").addClass("flashGreen");
  checkPress(playerStep, 0);
});

$(".tlcornerPiece").on("mouseup", function() {
  $(".tlcornerPiece").removeClass("flashGreen");
});

$(".trcornerPiece").on("mousedown", function() {
  $('#redSound')[0].play();
  $(".trcornerPiece").addClass("flashRed");
});

$(".trcornerPiece").on("mouseup", function() {
  $(".trcornerPiece").removeClass("flashRed");
  checkPress(playerStep, 1);
});

$(".blcornerPiece").on("mousedown", function() {
  $('#yellowSound')[0].play();
  $(".blcornerPiece").addClass("flashYellow");
});

$(".blcornerPiece").on("mouseup", function() {
  $(".blcornerPiece").removeClass("flashYellow");
  checkPress(playerStep, 2);
});

$(".brcornerPiece").on("mousedown", function() {
  $('#blueSound')[0].play();
  $(".brcornerPiece").addClass("flashBlue");
});

$(".brcornerPiece").on("mouseup", function() {
  $(".brcornerPiece").removeClass("flashBlue");
  checkPress(playerStep, 3);
});

function pushRandom() {
//  console.log(stepArray);
  stepArray.push(Math.floor(Math.random() * (3 - 0 + 1)) + 0);
  console.log(stepArray);
}

function playbackLoop() {
  
//  console.log("Start playback loop");
  $("#stepCounter").text(stepArray.length);
  
//  console.log(loopSteps);
  if (loopSteps) {
    checkScore();
//    console.log(currentStep);
    if (currentStep <= stepArray.length) {
//     console.log("Playback step " + currentStep + ": " + stepArray[currentStep]);
      switch (stepArray[currentStep]) {
        case 0:
          $(".tlcornerPiece").addClass("flashGreen");
          $('#greenSound')[0].play();
          break;
        case 1:
          $(".trcornerPiece").addClass("flashRed");
          $('#redSound')[0].play();
          break;
        case 2:
          $(".blcornerPiece").addClass("flashYellow");
          $('#yellowSound')[0].play();
          break;
        case 3:
          $(".brcornerPiece").addClass("flashBlue");
          $('#blueSound')[0].play();
          break;
        default:
          break;
      }
      currentStep++;
    window.setTimeout(lightsOff, 1000);
    window.setTimeout(playbackLoop, 2000);
    } else {
      loopSteps = false;
    }
  }
}

function checkPress(step, pressed) {
    roundComplete = true;
  if (pressed == stepArray[step]) {
//    console.log("Matched step: " + step);
    playerStep++;
  } else if(strictMode){
    resetGame();
  } else {
//    console.log("nope!");
    playerStep = 0;
    $(".tlcornerPiece").addClass("flashGreen");
    $(".trcornerPiece").addClass("flashRed");
    $(".blcornerPiece").addClass("flashYellow");
    $(".brcornerPiece").addClass("flashBlue");
    $('#greenSound')[0].play();
    $('#redSound')[0].play();
    $('#yellowSound')[0].play();
    $('#blueSound')[0].play();
    roundComplete = false;
    loopSteps = true;
    playerStep = 0;
    currentStep = 0;
    window.setTimeout(wrongPress, 500);
    window.setTimeout(playbackLoop, 2500);
  }
  if (step == stepArray.length - 1 && roundComplete) {
 //   console.log("Round complete!");
    playerStep = 0;
    currentStep = 0;
    loopSteps = true;
    pushRandom();
    window.setTimeout(playbackLoop, 2500);
  }
}

function lightsOff(){  
  $(".tlcornerPiece").removeClass("flashGreen");
  $(".trcornerPiece").removeClass("flashRed");
  $(".blcornerPiece").removeClass("flashYellow");
  $(".brcornerPiece").removeClass("flashBlue");
}

function wrongPress(){
  $(".tlcornerPiece").removeClass("flashGreen");
  $(".trcornerPiece").removeClass("flashRed");
  $(".blcornerPiece").removeClass("flashYellow");
  $(".brcornerPiece").removeClass("flashBlue");
}

function resetGame(){
    currentStep = 0;
    playerStep = 0;
    stepArray = [];
    loopSteps = true;
    roundComplete = false;
  //  console.log("reset");
    playerStep = 0;
    $(".tlcornerPiece").addClass("flashGreen");
    $(".trcornerPiece").addClass("flashRed");
    $(".blcornerPiece").addClass("flashYellow");
    $(".brcornerPiece").addClass("flashBlue");
    pushRandom();
    window.setTimeout(wrongPress, 500);
    window.setTimeout(playbackLoop, 2500);
}



function checkScore(){
    if(stepArray.length == 21){
      alert("You win!");
      resetGame();
  }
}


pushRandom();
playbackLoop();
              
            
!
999px

Console