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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <head>

</head>
<body>
  <div id="container">
    <div id="center">
      <h1>Simon</h1>
      <span id="textbox"></span>
      <button id="startBtn" class="disabled"></button>
      <label id="startBtnLabel">Start</label>
      <button id="strictBtn" class="disabled"></button>
      <label id="strictBtnLabel">Strict</label>
      <label id="onLabel">On</label>
      <label class="switch" id='toggle'>
        <input type="checkbox" id='switch'>
        <div class="slider"></div>
      </label>
      <label id="offLabel">Off</label>
    </div>
    <div id="btn1" value="1" class="disabled"></div>
    <div id="btn2" value="2" class="disabled"></div>
    <div id="btn3" value="3" class="disabled"></div>
    <div id="btn4" value="4" class="disabled"></div>
  </div>
</body>
              
            
!

CSS

              
                #container{
  width: 400px;
  height: 400px;
  background-color: black;
  border-radius: 50%;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
#center{
  width: 200px;
  height: 200px;
  background-color: white;
  border-radius: 50%;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
#center h1{
  text-align:center;
}
#textbox{
  width: 60px;
  height: 40px;
  background-color: gray;
  position: absolute;
  border-radius:20%;
  left: 20%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align:center;
  line-height: 40px;
}
#startBtn{
  width: 20px;
  height: 20px;
  background-color: gray;
  position: absolute;
  border-radius:50%;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
}
#startBtnLabel{
  width: 20px;
  height: 20px;
  position: absolute;
  border-radius:50%;
  left: 48%;
  top: 56%;
  transform: translate(-50%, -50%);
}
#strictBtn{
  width: 20px;
  height: 20px;
  background-color: gray;
  position: absolute;
  border-radius:50%;
  left: 75%;
  top: 46%;
  transform: translate(-50%, -50%);
}
#strictBtnLabel{
  width: 20px;
  height: 20px;
  position: absolute;
  border-radius:50%;
  left: 73%;
  top: 56%;
  transform: translate(-50%, -50%);
}
#toggle{
  position: absolute;
  left: 50%;
  top: 75%;
  transform: translate(-50%, -50%);
}
#onLabel{
  position: absolute;
  left: 25%;
  top: 75%;
  transform: translate(-50%, -50%);
}
#offLabel{
  position: absolute;
  left: 75%;
  top: 75%;
  transform: translate(-50%, -50%);
}
/*
#btn1{
  border: solid 90px green;
  height:210px;
  width:210px;
  border-radius: 50%;
  background-color:transparent;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}*/
#btn1{
  background-color:green;
  height:190px;
  width:190px;
  border-radius: 100% 0% 0% 0%;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-100%, -100%);
  z-index:-1;
}
#btn2{
  background-color:red;
  height:190px;
  width:190px;
  border-radius: 0% 100% 0% 0%;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(0, -100%);
  z-index:-1;
}
#btn3{
  background-color:blue;
  height:190px;
  width:190px;
  border-radius: 0% 0% 100% 0%;
  position: absolute;
  left: 50%;
  top: 50%;
  z-index:-1;
}
#btn4{
  background-color:purple;
  height:190px;
  width:190px;
  border-radius: 0% 0% 0% 100%;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-100%, 0%);
  z-index:-1;
}



/* *****Below here is not my code: its just for the toggle switch**** */
/* The switch - the box around the slider */
.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

/* Hide default HTML checkbox */
.switch input {display:none;}

/* The slider */
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

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

input:checked + .slider {
  background-color: #2196F3;
}

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

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


              
            
!

JS

              
                $(document).ready(function() {
  //All that is left is to disable everything when the slider turns off and to add noises
  $('#switch').click(function(){
    if ($('#switch').prop("checked") === true){
      $('.disabled').prop("disabled", true);
    }
    else{
      $('.disabled').prop("disabled", false);
    }
  })
  
  $("#strictBtn").click(function() {
    //alert($(this).css("background-color"));
    if ($(this).css("background-color") === "rgb(128, 128, 128)") {
      $(this).css("background-color", "red");
      $(this).prop("checked", true);
    } else if ($(this).css("background-color") === "rgb(255, 0, 0)") {
      $(this).css("background-color", "rgb(128, 128, 128)");
      $(this).prop("checked", false);
    }
  });
  
  /*
  $("#strictBtn").click(function() {
    if ($(this).css("background-color") === "rgb(255, 0, 0)") {
      $(this).css("background-color", "blue");
      $(this).prop("checked", true);
    } else if ($(this).css("background-color") === "rgb(0, 0, 255)") {
      $(this).css("background-color", "red");
      $(this).prop("checked", false);
    }
  });*/

  function lightUp(btNum) {
    $("#btn" + btNum).fadeOut().delay(100).fadeIn();
    //alert(btNum);
    if(parseInt(btNum) === 1){
      $.playSound("https://s3.amazonaws.com/freecodecamp/simonSound1.mp3");
    }
    else if(parseInt(btNum) === 2){
      $.playSound("https://s3.amazonaws.com/freecodecamp/simonSound2.mp3");
    }
    else if(parseInt(btNum) === 3){
      $.playSound("https://s3.amazonaws.com/freecodecamp/simonSound3.mp3");
    }
    else{
      $.playSound("https://s3.amazonaws.com/freecodecamp/simonSound4.mp3");
    }

  }

  function game(key) {
    var step = 1;
    var timer;
    var userArr = [];
    var k = 0;
    var userTurn = false;
    function timeoutloop(steps) {
      $('#textbox').html(steps);
      userTurn = false;
      timer = setTimeout(function() {
        lightUp(key[k]);
        k++;
        if (k < steps) {
          //alert("step: "+steps+" K: "+k+ " key: "+key[k]);
          timeoutloop(steps);
        } else {
          userTurn = true;
        }
      }, 1000);
    }
    timeoutloop(step);
    $("#startBtn").click(function() {
      step = 0;
      //key = [];
      userTurn = false;
      clearTimeout(timer);
    });
    $('#switch').click(function(){
      step = 0;
      //key = [];
      userTurn = false;
      clearTimeout(timer);
      $('#textbox').html("");
    })
    $("#btn1, #btn2, #btn3, #btn4").click(function() {
      if (userTurn === true) {
        //animate clicked button, add it to the user list
        lightUp($(this).attr('value'));
        userArr.push($(this).attr('value'));
        if(userArr.length === step && step !== 0){
          var checKey = [];
          for(var j = 0; j < key.length; j++){
            checKey.push(key[j]);
          }
          var correct = true;
          checKey.splice(step);
          for(var i = 0; i < checKey.length; i++){
            if(checKey[i] !== parseInt(userArr[i])){
              correct = false;
            }
          }
          if(correct === true){
            k=0;
            userArr = [];
            step++;
            timeoutloop(step);
          }
          else{
            k=0;
            userArr = [];
            step = 1;
            if ($("#strictBtn").prop("checked") === true) {
              $( "#startBtn" ).trigger( "click" );
            } else {
              timeoutloop(step);
            }
          }
        }
      }
    });

    //while(key.splice(0, userArr.length) === userArr)
  }

  function keygen(caller) {
    //generate key
    var key = [];
    for (var i = 0; i < 20; i++) {
      key.push(Math.floor(Math.random() * (5 - 1)) + 1);
    }
    if (caller === true) {
      //call main game
      game(key);
    } else {
      return key;
    }
  }
  
  

  var key = keygen(false);
  var running = false;
  $("#startBtn").click(function() {
    if ($("#onoff").is(":checked") === false) {
      //alert($("#strictBtn").prop("checked")=== true);
      if ($("#strictBtn").prop("checked") === true) {
        keygen(true);
      } else {
        game(key);
      }
    }
  });
});

              
            
!
999px

Console