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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <link href="https://fonts.googleapis.com/css?family=Anton|Share+Tech+Mono" rel="stylesheet">
  <div class = "game">
    <div class = "row">
      <div class = "col-xs-6 green press tl inline" id = "g"></div>
      <div class = "col-xs-6 red press tr inline" id = "r"></div>
    </div>
    <div class = "row">
      <div class = "col-xs-6 yellow press bl inline" id = "y"></div>
      <div class = "col-xs-6 blue press br inline" id = "b"></div>
    </div>
  <div class = "menu">
    <div class = "row" id = "title">Simon Game</div>
    <div class = "row options">
      <div class = "col-xs-4"><span id = "cnt">--</span><br><button class = "config" id = "count">Count</button></div>
      <div class = "col-xs-4"><span id = "startDisp">&#10686;</span><br><button class = "config" id = "strt">Start</button></div>
      <div class = "col-xs-4"><span id = "strictDisp">&#10686;</span><br><button class = "config" id = "strct">Strict</button></div>
    </div>
    <div class = "row"><label class="switch">
  <input type="checkbox" id="onoff">
  <div class="slider"></div>
</label></div>
  </div>
</div>
            
          
!

CSS

            
              body {
  background-image: url("http://www.designbolts.com/wp-content/uploads/2013/02/Free-Seamless-Dry-Wood-texture-For-3D-MAX-Mapping.jpg");
  background-repeat: repeat-y|repeat-x;
}

.br{
  border-bottom-right-radius : 100%;
}
.bl{
  border-bottom-left-radius : 100%;
}
.tl{
  border-top-left-radius : 100%;
}
.tr{
  border-top-right-radius : 100%;
}
.red{background-color: #D04F4F;}
.fullRed{background-color: #FF7B7B;}
.green{background-color: #9DD04F;}
.fullGreen{background-color: #CCFF7E;}
.blue{background-color: #4F8AD0;}
.fullBlue{background-color: #82BBFF;}
.yellow{background-color: #DEDE50;}
.fullYellow{background-color: #FFF57B;}

.inline{
  display: inline-block;
}

.press {
  position: relative;
  margin: auto;
  text-align: center;
  margin: 0 auto;
  height: 235px;
  border: 16px solid #505050;
  /*box-shadow: 5px 5px 5px #3E3E3E;*/
  -webkit-box-shadow: -1px 4px 20px 0px #3E3E3E;
  -moz-box-shadow:    -1px 4px 20px 0px #3E3E3E;
  box-shadow:         -1px 4px 20px 0px #3E3E3E;
}

.game {
  width: 450px;
  height: 450px;
  background-color: #505050;
  border-radius: 100%;
  position: relative;
  margin: auto;
  top: 8vh;
  text-align: center;
}

.menu {
  padding-top: 35px;
  font-family: 'Share Tech Mono', monospace;
  width: 200px;
  height: 200px;
  color: #505050;
  background-color: #F0DEA2;
  border-color: #505050;
  border-style: solid;
  border-width: 10px;
  border-radius: 100%;
  margin: auto;
  text-align: center;
  position : absolute;
  top: 54.75%;
  left: 54.75%;
  margin: -122px 0 0 -122px;
}

.options {
  padding-left: 0px;
  padding-right: 0px;
  width: 190px;
  text-align: right;
}

.config {
  background-color: transparent;
  border-color: transparent;
}

.config:hover {
  text-decoration: underline;
}

#onoff {
  margin-top: 10px;
}

/**/
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 20px;
}
.switch input {display:none;}
/* The slider */
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #D04F4F;
  -webkit-transition: .4s;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 12px;
  width: 12px;
  left: 4px;
  bottom: 4px;
  background-color: #F0DEA2;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .slider {
  background-color: #9DD04F;
}

input:focus + .slider {
  box-shadow: 0 0 1px #9DD04F;
}

input:checked + .slider:before {
  -webkit-transform: translateX(18px);
  -ms-transform: translateX(18px);
  transform: translateX(18px);
}
/**/

#title {font-family: 'Anton', sans-serif; font-size: 30px;}

.rw{
  margin-bottom:-4px;
}


            
          
!

JS

            
              var clickable = false;
var gameOn = false;
var strict = false;
var turns = 1;
var count = 0;
var countUp = 0;
var simonArr = [];
var userArr = [];
var display = document.getElementById('cnt');
// --- AUDIO --- //
var audG = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3')
var audR = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound2.mp3')
var audY = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound3.mp3')
var audB = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound4.mp3')
var audErr = new Audio('https://d1490khl9dq1ow.cloudfront.net/sfx/mp3preview/buzz-error_G1eQPd4_.mp3');
  // --- GAMEPLAY --- //
function begin() {
  simonArr = [];
  userArr = [];
  count = 0;
  countUp = 0;
  turns = 1;
  simonAdd();
  setTimeout(simonSays, 700);
}

function simonAdd() {
  simonArr.push(Math.floor(Math.random() * 4) + 1);
  count++;
}
function simonSays() {
  display.innerHTML = count;
  output(simonArr[countUp]);
  countUp++;
  if (countUp < simonArr.length && gameOn){
    setTimeout(simonSays, 700);
  }
  userStart();
}
function userStart() {
  userArr = [];
  clickable = true;
}

function userInput() {
  console.log("User: " + userArr + " | Simon: " + simonArr);
  if (userArr[userArr.length - 1] === simonArr[userArr.length - 1]) {
    if (userArr.length == simonArr.length) {
      clickable = false;
      if (simonArr.length <= 20) {
        countUp = 0;
        simonAdd();
        setTimeout(simonSays, 1000);
      } else {
        gameWin();
      }
    }
  } else if (strict) {
    audErr.play();
    clickable = false;
    turns--;
    console.log("turns: " + turns);
    if (turns <= 0) {
      gameOver();
    } else {
      countUp = 0;
      setTimeout(simonSays, 1000);
    }
  } else {
    audErr.play();
    countUp = 0;
    setTimeout(simonSays, 1000);
  }
}

function gameOver() {
  display.innerHTML = "LOSE";
  clickable = false;
  //document.getElementById("checkbox").checked = false;
}

function gameWin() {
  display.innerHTML = "WIN";
  clickable = false;
  //document.getElementById("checkbox").checked = false;
}
// --- MECHANICS --- //
function output(num) {
  switch (num) {
    case 1:
      audG.play();
      $("#g").toggleClass('fullGreen');
      setTimeout(pauseG, 500);
      break;
    case 2:
      $("#r").toggleClass('fullRed');
      audR.play();
      setTimeout(pauseR, 500);
      break;
    case 3:
      $("#y").toggleClass('fullYellow');
      audY.play();
      setTimeout(pauseY, 500);
      break;
    case 4:
      $("#b").toggleClass('fullBlue');
      audB.play();
      setTimeout(pauseB, 500);
      break;
  }
}

function pauseG() {
  $("#g").toggleClass('fullGreen');
}

function pauseR() {
  $("#r").toggleClass('fullRed');
}

function pauseY() {
  $("#y").toggleClass('fullYellow');
}

function pauseB() {
  $("#b").toggleClass('fullBlue');
}

function pause() {}
// --- STATE CHANGES --- //
onoff.onclick = function() {
  gameOn = !gameOn;
  console.log("Status[gameOn]: " + gameOn);
  if (!gameOn) {
    var html = document.getElementById('startDisp');
    html.innerHTML = '&#10686;';
    display.innerHTML = "--";
  }
}
strt.onclick = function() {
  var html = document.getElementById('startDisp');
  if (gameOn) {
    begin();
    html.innerHTML = '&#10687;';
  } else {
    html.innerHTML = '&#10686;';
  }
}
strct.onclick = function() {
  var html = document.getElementById('strictDisp');
  if (!strict) {
    html.innerHTML = '&#10687;'
  } else {
    html.innerHTML = '&#10686;';
  }
  strict = !strict;
}
$("#g").on("mousedown", function() {
  if (clickable && gameOn) {
    $("#g").toggleClass('fullGreen');
    audG.play();
    userArr.push(1);
    userInput();
  }
}).on("mouseup", function() {
  if (gameOn) {
    $("#g").toggleClass('fullGreen');
  }
});
$("#r").on("mousedown", function() {
  if (clickable && gameOn) {
    $("#r").toggleClass('fullRed');
    audR.play();
    userArr.push(2);
    userInput();
  }
}).on("mouseup", function() {
  if (gameOn) {
    $("#r").toggleClass('fullRed');
  }
});
$("#y").on("mousedown", function() {
  if (clickable && gameOn) {
    $("#y").toggleClass('fullYellow');
    audY.play();
    userArr.push(3);
    userInput();
  }
}).on("mouseup", function() {
  if (gameOn) {
    $("#y").toggleClass('fullYellow');
  }
});
$("#b").on("mousedown", function() {
  if (clickable && gameOn) {
    $("#b").toggleClass('fullBlue');
    audB.play();
    userArr.push(4);
    userInput();
  }
}).on("mouseup", function() {
  if (gameOn) {
    $("#b").toggleClass('fullBlue');
  }
});
            
          
!
999px

Console