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

              
                <div id="sounds">
  <audio id="sound1">
        <source src="https://s3.amazonaws.com/freecodecamp/simonSound1.mp3" type="audio/mpeg">
    </audio>
  <audio id="sound2">
        <source src="https://s3.amazonaws.com/freecodecamp/simonSound2.mp3" type="audio/mpeg">
    </audio>
  <audio id="sound3">
        <source src="https://s3.amazonaws.com/freecodecamp/simonSound3.mp3" type="audio/mpeg">
    </audio>
  <audio id="sound4">
        <source src="https://s3.amazonaws.com/freecodecamp/simonSound4.mp3" type="audio/mpeg">
    </audio>
</div>
<p class="alert alert-info text-center" id="gameNotify"></p>
<div class="simon">
  <div class="circle">
    <div class="quarter green" id="green"></div>
    <div class="quarter red" id="red"></div>
    <div class="quarter yellow" id="yellow"></div>
    <div class="quarter blue" id="blue"></div>
  </div>
  <div class="cutout">
    <div class="gameButtons text-center">
      <button class="btn btn-primary" id="start">Start</button>
      <button class="btn btn-warning" id="restart">Restart</button>
      <label class="switch">
        <input class="strict toggle" id="checkbox" type="checkbox" checked>
        <div class="strict slider"></div>
      </label>
      <h3>Your Simon Game</h3>
      <label class="hard switch">
        <input class="hard toggle" id="checkbox" type="checkbox">
        <div class="slider"></div>
       </label>
    </div>
  </div>
</div>
<br>
<div class="well">
  <p class="text-center well">Current Score: <span id='count'>0</span></p>
<div class="well">
  <p class="text-center">Game Records:</p>
  <ol class="text-center" id="prevGames">
  </ol>
</div>
</div>
</div>

              
            
!

CSS

              
                #restart {
  display: none;
}
.active.green {
  background-color: #00ff55 !important;
}
.active.red {
  background-color: #ff0000 !important;
}
.active.yellow {
  background-color: #ffff00 !important;
}
.active.blue {
  background-color: #0000ff !important;
}

#prevGames {
  list-style-type:none
}

.simon {
  position: relative;
  width: 500px;
  height: 500px;
  margin: 0 auto;
  z-index: 0;
}
.quarter {
  position: absolute;
  width: 50%;
  height: 50%;
  transition: background-color 0.2s ease-in-out;
  box-shadow: 0px 0px 10px #00000;
}
#green {
  top: 0;
  left: 0;
  background-color: #009933;
  border-radius: 100% 0 0 0;
}
#red {
  top: 0;
  right: 0;
  background-color: #990000;
  border-radius: 0 100% 0 0;
}
#yellow {
  bottom: 0;
  left: 0;
  background-color: #cccc00;
  border-radius: 0 0 0 100%;
}
#blue {
  bottom: 0;
  right: 0;
  background-color: #000099;
  border-radius: 0 0 100% 0;
}
.cutout {
  width: 50%;
  height: 50%;
  background-color: white;
  position: absolute;
  top: 25%;
  left: 25%;
  border-radius: 50%;
  z-index: 1;
  box-shadow: inset 0px 0px 10px #000000;
}
.switch {
  top: 18px;
}
.switch-label {
  margin-left: 58px;
}
.gameButtons {
  margin: 15% 0 0 0;
  z-index: 2;
}



.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}
.switch .toggle {display:none;}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
  border-radius: 34px;
}
.strict.slider:before {
  position: absolute;
  content: " Strict ";
  height: 26px;
  width: 40px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  border-radius: 12px;
  -webkit-transition: .4s;
  transition: .4s;
}
.slider:before {
  position: absolute;
  content: " HARD ";
  height: 26px;
  width: 40px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  border-radius: 12px;
  -webkit-transition: .4s;
  transition: .4s;
}
.toggle:checked + .slider {
  background-color: #00cc00;
}
.toggle:focus + .slider {
  box-shadow: 0 0 1px #00cc00;
}
.toggle:checked + .slider:before {
  -webkit-transform: translateX(12px);
  -moz-transform: translateX(12px);
  -ms-transform: translateX(12px);
  -o-transform: translateX(12px);
  transform: translateX(12px);
}
.hard.switch {
  -webkit-transition: all 0.5s ease-in-out;
  transition: all 0.5s ease-in-out;
}
              
            
!

JS

              
                $(document).ready(function() {
  var order = [];
  var sequence = [];
  var rolling = 0;
  var count = 0;
  var running = false;
  var lightNum = 0;
  var light;
  var lightsGoing = false;
  var strictOn = true;
  var hard = false;
  var fail = false;
  var hardRotateNum = 90;
  var countTimeout;
  function getRandomInt() {
    return Math.floor(Math.random() * (4 - 1 + 1)) + 1;
  }
  function endGame() {
    $("#restart").hide();
    running = false;
    order = [];
    sequence = [];
    $("#gameNotify").text("Game over...");
    $("#start").show();
    $("#prevGames").append("<li>" + count + "</li>");
    $(".simon").rotate({
      angle: 0,
      animateTo: 360,
      easing: $.easing.easeInOutElastic
    });
    $(".simon .cutout").rotate({
        animateTo: 0,
        easing: $.easing.easeInOutElastic
    });
    count = -1;
  }
  function checkTimeInterval(num) {
    clearInterval(countTimeout);
    countTimeout = setInterval(function() {
      num--
      if(num == 0) endGame();
    }, 1000);
  }
  function lightUp(item, num) {
    $(item).addClass("active");
    if(strictOn && hard) $("#sound" + getRandomInt())[0].play();
    else $("#sound" + num)[0].play();
    setTimeout(function () {
      $(item).removeClass("active");
    }, 300);
  }  
  function lightUpOrder() {
      switch(order[lightNum]) {
        case 1:
          setTimeout(function () {
            lightUp(".green", 1);
           }, 1000);
          break;
        case 2:
          setTimeout(function () {
            lightUp(".red", 2);
           }, 1000);
          break;
        case 3:
          setTimeout(function () {
            lightUp(".yellow", 3);
           }, 1000);
          break;
        case 4:
          setTimeout(function () {
            lightUp(".blue", 4);
           }, 1000);
          break;
        }
    lightNum++;
    if(lightNum == order.length) {
      lightNum = 0;
      lightsGoing = false;
      clearInterval(light);
      if(strictOn && hard) {
        $(".simon").rotate({
          animateTo: hardRotateNum,
          easing: $.easing.easeInOutElastic
        });
        $(".simon .cutout").rotate({
          animateTo: -hardRotateNum,
          easing: $.easing.easeInOutElastic
        })
        hardRotateNum = getRandomInt() * 90;
      }
      if(strictOn) checkTimeInterval(5);
    }
  }
  function victory() {
    $("#restart").hide();
    running = false;
    order = [];
    sequence = [];
    $("#gameNotify").text("You Win");
    $("#start").show();
    $("#prevGames").append("<li>" + "You Won: "+ count + "</li>");
    count = -1;
  }  
  function createNew() {
    var rand = getRandomInt();
    order.push(rand);
    count++;
    light = setInterval(lightUpOrder, 750);
    lightsGoing = true;
    $("#count").text(count);
  }
  function replay() {
    light = setInterval(lightUpOrder, 750);
    lightsGoing = true;
    strictOn = false;
    fail = false;
    $("#gameNotify").text("Please try again");
    $("#count").text(count);
  }
  function checkGame() {
    if(count >= 20) victory();
    for(var a = 0; a < order.length; a++) {
      if(sequence[a] !== order[a] && strictOn) endGame();
      else if(sequence[a] !== order[a] && !strictOn) fail = true;
    }
    sequence = [];
    if(running && !fail) createNew();
    if(running && fail) replay();
  }
  function seq() {
    if(sequence.length > 21) endGame();
    if(running && !lightsGoing) {
      $("#gameNotify").text("");
      if(order[rolling] != sequence[rolling]) endGame();
      rolling++;
      if(sequence.length == order.length) {
        rolling = 0;
        checkGame();
      } else if(strictOn) checkTimeInterval(5);
    } else if(lightsGoing) {
      $("#gameNotify").text("Please don't press while your learning a new sequence");
      sequence = [];
    } else {
      sequence = [];
      $("#gameNotify").text("The game is over.");
    }
  }
  $("#restart").click(function() {
    count = -1;
    sequence = [];
    order = [];
    rolling = 0;
    lightNum = 0;
    lightsGoing = false;
    clearInterval(light);
    checkGame();
  });
  $(".green").click(function() {
    clearInterval(countTimeout);
    lightUp(".green", 1);
    sequence.push(1);
    seq();
  });
  $(".red").click(function() {
    clearInterval(countTimeout);
    lightUp(".red", 2);
    sequence.push(2);
    seq();
  });
  $(".yellow").click(function() {
    clearInterval(countTimeout);
    lightUp(".yellow", 3);
    sequence.push(3);
    seq();
  });
  $(".blue").click(function() {
    clearInterval(countTimeout);
    lightUp(".blue", 4);
    sequence.push(4);
    seq();
  });
  $("#start").click(function() {
    running = true;
    createNew();
    $("#restart").show();
    $("#start").hide();
    $("#gameNotify").text("");
  });
  $('.strict.toggle').click(function(){
    if($(this).is(":checked")){
      strictOn = true;
      $('.hard.switch').css({'opacity': 1});
    }
    else if($(this).is(":not(:checked)")){
      strictOn = false;
      $('.hard.switch').css({'opacity': 0});
    }
  });
  $('.hard.toggle').click(function(){
    if($(this).is(":checked")){
      hard = true;
    }
    else if($(this).is(":not(:checked)")){
      hard = false;
      $(".simon .cutout").rotate({
        animateTo: 0,
        easing: $.easing.easeInOutElastic
      });
      $(".simon").rotate({
        animateTo: 0,
        easing: $.easing.easeInOutElastic
      });
    }
  });
});
              
            
!
999px

Console