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

              
                <audio id="sound-red" src="https://s3.amazonaws.com/freecodecamp/simonSound4.mp3" type="audio/mpeg"></audio>
<audio id="sound-blue" src="https://s3.amazonaws.com/freecodecamp/simonSound3.mp3" type="audio/mpeg"></audio>
<audio id="sound-yellow" src=" https://s3.amazonaws.com/freecodecamp/simonSound2.mp3" type="audio/mpeg"></audio>
<audio id="sound-green" src="https://s3.amazonaws.com/freecodecamp/simonSound1.mp3" type="audio/mpeg"></audio>


<div class="text-center" id="header">
  <H1>Simon Game</h1>
  <h5>By Wynand Theron</h5>
  <h2 id = "computer-turn">Computer Turn</h2>
  <h2 id = "player-turn">Player Turn</h2>
  <h2 id = "to-start">Push start button to play!</h2>
</div>
<div class="container">
  <div class="board">
    <div class="pad red" id="0"></div>
    <div class="pad blue" id="1"></div>
    <div class="pad green" id="2"></div>
    <div class="pad yellow" id="3"></div>
    <div class="control-panel">
      <div id="display"><strong></strong></div>
      <div class="btn btn-danger inline" id="start">START</div>
      <div class="btn btn-warning inline" id="strict">Strict</div>
      <div class="btn inline" id="restart">Restart</div>
      <div class="inline" id="strict-light"></div>
      <div id="switch">
        <p class="inline">ON</p>
        <div class="inline" id="outer-switch">
          <div id="inner-switch"></div>
        </div>
        <p class="inline">OFF</p>
      </div>
    </div>
        <div id="anouncement1">
          <p id="anounce1-text">Correct!</p>
          <div class="button">Start next round</div>
        </div>
        <div id="anouncement2">
          <p id="anounce2-text">You win!</p>
          <div class="newGame">New Game</div>
        </div>
        <div id="anouncement3">
          <p id="anounce3-text">Game Over!</p>
          <div class="newGame">New Game</div>
        </div>
        <div id="anouncement4">
          <p id="anounce4-text">Wrong move</p>
          <div class="tryAgain">try again!</div>
        </div>
        
   </div>
</div>
  

              
            
!

CSS

              
                body {
  background-image: url("http://www.powerpointhintergrund.com/uploads/2017/05/solid-color-background-teal-free-blue-lor-backgrounds-just--26.jpeg");
}

#header {
  height: 230px;
}

h1 {
  margin-top: 30px;
  color: white;
  font-family: 'Gloria Hallelujah', bold;
  font-size: 50px;
}

h5 {
 margin-bottom: 10px; 
}

#computer-turn {
  color: red;
  background-color: rgba(250,250,250,0.3);
  margin: 0 auto;
  width: 40%;
  padding: 10px;
  /*color: rgba(250,250,250,0.5);*/
  border: 5px solid black;
  border-radius: 10px;
  font-size : 50px;
  margin-top: 20px;
  font-weight: bold;
}

#player-turn {
  color: green;
  background-color: rgba(250,250,250,0.3);
  margin: 0 auto;
  width: 40%;
  padding: 10px;
  /*color: rgba(250,250,250,0.5);*/
  border: 5px solid black;
  border-radius: 10px;
  font-size : 50px;
  margin-top: 20px;
  font-weight: bold;
}

#to-start {
  color: Black;
  background-color: rgba(250,250,250,0.3);
  margin: 0 auto;
  width: 60%;
  padding: 10px;
  /*color: rgba(250,250,250,0.5);*/
  border: 5px solid black;
  border-radius: 10px;
  font-size : 50px;
  margin-top: 20px;
  font-weight: bold;
}


.container {
  margin: 0px auto;
  text-align: center;
  margin-bottom: 100px;
}

.board {
  margin: 0px auto;
  height: 500px;
  width: 500px;
  border: 15px solid #444444;
  border-radius: 500px;
  -webkit-box-shadow: 1px 10px 14px 4px rgba(0,0,0,0.75);
  -moz-box-shadow: 1px 10px 14px 4px rgba(0,0,0,0.75);
  box-shadow: 1px 10px 14px 4px rgba(0,0,0,0.75);
  
}

.pad {
  float: left;
  position: relative;
  height: 235px;
  width: 235px;
  border: 10px solid #000000;
  z-index: 1;
}

.red {
  background-color: hsl(0, 100%, 15%);
  border-radius: 250px 0 0 0;
}

.red:active {
  background-color: red;
}

.red.active {
  background-color: red;
  animation: fadeIn
}

.blue {
  background-color: hsl(240, 100%, 15%);
  border-radius: 0 250px 0 0;
}

.blue:active {
  background-color: blue;
}

.blue.active {
  background-color: blue;
}

.green {
  background-color: hsl(120, 100%, 10%);
  border-radius: 0 0 0 250px;
  -webkit-box-shadow: 0px 7px 13px 0px rgba(0,0,0,0.75);
  -moz-box-shadow: 0px 7px 13px 0px rgba(0,0,0,0.75);
  box-shadow: 0px 7px 13px 0px rgba(0,0,0,0.75);  
}

.green:active {
  background-color: green;
}

.green.active {
  background-color: green;
}

.yellow {
  background-color: hsl(60, 100%, 10%);
  border-radius: 0 0 250px 0;
  -webkit-box-shadow: 0px 7px 13px 0px rgba(0,0,0,0.75);
  -moz-box-shadow: 0px 7px 13px 0px rgba(0,0,0,0.75);
  box-shadow: 0px 7px 13px 0px rgba(0,0,0,0.75);
}

.yellow:active {
  background-color: yellow;
}


.yellow.active {
  background-color: yellow;
}

.control-panel {
  width: 260px;
  height: 260px;
  margin-left: 105px;
  margin-top: 110px;
  background-color: #999999;
  border: 15px solid #000000;
  border-radius: 130px;
  position: absolute;
  z-index: 2;
  
  -webkit-box-shadow: 0px 7px 13px 0px rgba(0,0,0,0.75);
  -moz-box-shadow: 0px 7px 13px 0px rgba(0,0,0,0.75);
  box-shadow: 0px 7px 13px 0px rgba(0,0,0,0.75);
}

.inline {
  margin-top: 20px;
  display: inline-block;
  vertical-align: middle;    
}

#display {
  color: #990000;
  text-shadow: -1px -1px 11px rgba(150, 0, 0, 1);
  background-color:#400000;
  font-size: 30px;
  margin: 0px auto;
  margin-top: 30px;
  height: 60px;
  width: 70px;
  border: 3px solid #000000;
  border-radius: 5px;
  -webkit-box-shadow: inset 13px -10px 27px -2px rgba(0,0,0,0.75);
  -moz-box-shadow: inset 13px -10px 27px -2px rgba(0,0,0,0.75);
  box-shadow: inset 13px -10px 27px -2px rgba(0,0,0,0.75);
}

.btn {
  border: 1px solid #000000;
  -webkit-box-shadow: inset -16px -17px 27px -12px rgba(0,0,0,0.75);
  -moz-box-shadow: inset -16px -17px 27px -12px rgba(0,0,0,0.75);
  box-shadow: inset -16px -17px 27px -12px rgba(0,0,0,0.75);
}

.btn:active {
  border: 1px solid #000000;
  -webkit-box-shadow: inset 17px 18px 27px -12px rgba(0,0,0,0.75);
  -moz-box-shadow: inset 17px 18px 27px -12px rgba(0,0,0,0.75);
  box-shadow: inset 17px 18px 27px -12px rgba(0,0,0,0.75);
}



#outer-switch {
  width: 50px;
  height: 25px;
  background-color: grey;
  border: 1px solid #000000;
}

#inner-switch {
  width: 25px;
  height: 25px;
  background-color: grey;
  float: right;
  border: 1px solid black;
  -webkit-box-shadow: 0px 7px 13px 0px rgba(0,0,0,0.75);
  -moz-box-shadow: 0px 7px 13px 0px rgba(0,0,0,0.75);
  box-shadow: 0px 7px 13px 0px rgba(0,0,0,0.75);
}

#strict-light {
  background-color: hsl(0, 100%, 13%);
  height: 10px;
  width: 10px;
  border: 0.5px solid black;
  border-radius: 5px;
  margin-bottom: 2px;
  margin-top: 2px;
}

#anouncement1 {
  visibility: hidden;
  font-size: 30px;
  background-color: rgb(204, 204, 204);
  height: 200px;
  width: 400px;
  margin-left: 35px;
  margin-top: 130px;
  padding-top: 40px;
  border: 10px solid black;
  border-radius: 20px;
  position: absolute;
  z-index: 9999;
}


.button {
  font-size: 30px;
  color: white;
  transition: transform .2s;
  text-shadow: 2px 1px 18px rgba(0, 0, 0, 1);
}

.button:hover {
  transform: scale(1.5);
  cursor: pointer;
}

#anouncement2 {
  visibility: hidden;
  font-size: 30px;
  background-color: rgb(204, 204, 204);
  height: 200px;
  width: 400px;
  margin-left: 35px;
  margin-top: 130px;
  padding-top: 40px;
  border: 10px solid black;
  border-radius: 20px;
  position: absolute;
  z-index: 9999;
}

.newGame {
  font-size: 30px;
  color: white;
  transition: transform .2s;
  text-shadow: 2px 1px 18px rgba(0, 0, 0, 1);
}

.newGame:hover {  
  transform: scale(1.5);
  cursor: pointer;
}

#anouncement3 {
  visibility: hidden;
  font-size: 30px;
  background-color: rgb(204, 204, 204);
  height: 200px;
  width: 400px;
  margin-left: 35px;
  margin-top: 130px;
  padding-top: 40px;
  border: 10px solid black;
  border-radius: 20px;
  position: absolute;
  z-index: 9999;
}


#anouncement4 {
  visibility: hidden;
  font-size: 30px;
  background-color: rgb(204, 204, 204);
  height: 200px;
  width: 400px;
  margin-left: 35px;
  margin-top: 130px;
  padding-top: 40px;
  border: 10px solid black;
  border-radius: 20px;
  position: absolute;
  z-index: 9999;
}

.tryAgain {
  font-size: 30px;
  color: white;
  transition: transform .2s;
  text-shadow: 2px 1px 18px rgba(0, 0, 0, 1);
}

.tryAgain:hover {  
  transform: scale(1.5);
  cursor: pointer;
}


              
            
!

JS

              
                $(document).ready(function(){
  
  var $compTurn = $("#computer-turn");
  var $playerTurn = $("#player-turn");
  $compTurn.hide();
  $playerTurn.hide();
  
  var $toStart = $("#to-start");
  $toStart.hide();
  
  var $soundRed = $("#sound-red")[0];
  var $soundBlue = $("#sound-blue")[0];
  var $soundYellow = $("#sound-yellow")[0];
  var $soundGreen = $("#sound-green")[0];
  
  const $allPads = document.querySelectorAll('.pad')
  const $redPad = document.querySelector('.red');
  const $bluePad = document.querySelector('.blue');
  const $greenPad = document.querySelector('.green');
  const $yellowPad = document.querySelector('.yellow');
  
  
  var count = 0;
  var off = "true";
  var computer = [];
  var player = [];
  var winner;
  var strict = "false";
  //console.log(); //to test
  
  
  $("#outer-switch").on("click", function(){ //to switch on/off
    if (off === "true") {
      alert("If you would wish to restart the game during the computer sequence, please wait for the sequence to finish before clicking restart!");
      $("#display").html("<strong>--</strong>");   
      $('#inner-switch').css("float","left");
      off = "false";
      $toStart.show();
    }else if (off === "false") {
      $("#display").html("");
      $('#inner-switch').css("float","right");
      count = 0; 
      computer =[];
      player =[];
      off = "true";
      $compTurn.hide();
      $playerTurn.hide();
      if (strict === "true") {
        $("#strict-light").css("background-color","hsl(0, 100%, 13%)");
        strict = "false";
      }
     }      
  });
  
  
  
  
  //to start, next round or new game
  $("#start,.button,.newGame").on("click", function(){ 
    if (off === "false") {
      count++;
      $("#display").html(count);
      $("#anouncement1").css("visibility","hidden");
      $("#anouncement2").css("visibility","hidden");
      $("#anouncement3").css("visibility","hidden");
      $("#anouncement4").css("visibility","hidden");
      $compTurn.show();
      $playerTurn.hide();
      $toStart.hide();
      computerTurn(); 
      playSeq(computer);
   }
 });
  
  
 $("#restart").on("click", function() {
   $compTurn.show();
   $playerTurn.hide();
   count = 0;
   computer = []; 
   count++;
   $("#display").html(count);
   computerTurn(); 
   playSeq(computer);
 }); 

  
  //fills computer arr and plays the sequence
  function computerTurn() { 
    while (computer.length < count) {
      computer.push(randomNum());
      //console.log(computer);                  
   }  
 };
    
  
  
  
  
  //iterates through computer arr and plays the sequence, called back in computerTurn function
  async function playSeq(seq) {
    for (const value of seq) {
      if (off === "false") { //for switching off during game
      await sleep(1500);
      $soundRed.load();
      $soundBlue.load();
      $soundGreen.load();
      $soundYellow.load();
      soundPlayer(value);
      await sleep(200);
      $allPads.forEach ( pad => pad.classList.remove("active"));
      }
    } if (off === "false") { //for switching off during game
      $playerTurn.show();
    }
      $compTurn.hide();
  };  
  
  
  //called back in async function above
  function soundPlayer(seqCode) {
  switch (seqCode) {
    case 0: 
      $soundRed.play();
      $allPads.forEach ( pad => pad.classList.remove("active"));
      $redPad.classList.add("active");
      break;
    case 1:
      $soundBlue.play();
      $allPads.forEach ( pad => pad.classList.remove("active"));
      $bluePad.classList.add("active");
      break;
    case 2:
      $soundGreen.play();
      $allPads.forEach ( pad => pad.classList.remove("active"));
      $greenPad.classList.add("active");
      break;
    case 3:
      $soundYellow.play();
      $allPads.forEach ( pad => pad.classList.remove("active"));
      $yellowPad.classList.add("active");
      break;
  } 
}
  
  //called back in async function above
  function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
  
  

  
  
  
  
  //for player turn
  $(".pad").on("click", function() {
    if (computer.length === count) { 
      $soundRed.load();
      $soundBlue.load();
      $soundGreen.load();
      $soundYellow.load();
      if (this.id === "0") {
        player.push(0);
        $soundRed.play();
      } else if (this.id === "1") {
        player.push(1);  
        $soundBlue.play();
      } else if (this.id === "2") {
        player.push(2);
        $soundGreen.play();
      } else if (this.id === "3") {
        player.push(3);
        $soundYellow.play();
      }
    }
    if (off === "false" && count > 0) {
      //console.log(player);
      win(computer,player);
    }
  });
  
  
 
 
  
 
  //generates a random number when called
  function randomNum() {
    return Math.floor(Math.random() * (3 - 0 + 1)) + 0;        
  };
  
  
  
  
  
  
   //switches strict mode on and off
  $("#strict").on("click", function(){ 
    if (strict === "false" && off === "false") {
      $("#strict-light").css("background-color","red");
      strict = "true";
    }else if (strict === "true") {
      $("#strict-light").css("background-color","hsl(0, 100%, 13%)");
      strict = "false";
    }
  });
  
  
 
  //to determine if player wins, next round or error
  function win(arr1,arr2){
    if(arr1.join('') === arr2.join('') && player.length < 20) {
      winner = "false";
      player = [];
      count+1;
      $("#display").html(count+1);
      $("#anouncement1").css("visibility","visible");      
      computerTurn();
        
    }else if (arr1.join('') === arr2.join('') && player.length === 20) {
      winner = "true";
      $("#anouncement2").css("visibility","visible");
      count = 0;
      computer = [];
      player = [];
            
    }else if (arr1[player.length-1] !== arr2[player.length-1]) {
      winner = "false";
      if (strict === "true") {
      $("#anouncement3").css("visibility","visible");
      computer = [];
      player = [];
      count= 0;
      $("#display").html(1);
    }else {
      $("#anouncement4").css("visibility","visible");
      $(".tryAgain").on("click", function(){
      $("#anouncement4").css("visibility","hidden");
      player = [];
      $playerTurn.hide();
      $compTurn.show();
      playSeq(computer);
      })
     }
    }
  };
 
  

 
});//end





              
            
!
999px

Console