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>
  <audio id="sound1" src="https://s3.amazonaws.com/freecodecamp/simonSound1.mp3" preload="auto"></audio>
  <audio id="sound2" src="https://s3.amazonaws.com/freecodecamp/simonSound2.mp3" preload="auto"></audio>
  <audio id="sound3" src="https://s3.amazonaws.com/freecodecamp/simonSound3.mp3" preload="auto"></audio>
  <audio id="sound4" src="https://s3.amazonaws.com/freecodecamp/simonSound4.mp3" preload="auto"></audio>
  <audio id="error" src="https://ia800209.us.archive.org/1/items/simo_game_audio/error.mp3" preload="auto"></audio>
  <audio id="victory" src="https://ia600209.us.archive.org/1/items/simo_game_audio/victory.mp3" preload="auto"></audio>
</head>

<div id="game"> 
    
<div id="circle">
  
  <h1>Simon</h1>   
  
  <div class="control">
    <div class="btn start"></div>
    <h3>START</h3>
  </div>
  
  <div id="bulb"></div>
  
  <div class="control">    
    <div class="btn strict"></div>
    <h3>STRICT</h3>
  </div>   
    
  <div id="screen">--</div>
  <h3>COUNT</h3>
  
</div>    
  
    <div class="square green" id="0"></div>
    <div class="square red" id="1"></div>
    <div class="square yellow" id="2"></div>
    <div class="square blue" id="3"></div>  
  
</div>
              
            
!

CSS

              
                body {  
  background: url('http://wallpapercave.com/wp/zwaIWUh.jpg') no-repeat;
  background-color: #314359;
  user-select: none;
  color: #314359;
}

#game {
  width: 550px;
  height: 550px;
  margin: 10vh auto;
  position: relative;
}

 #circle {
  width: 265px;  
  height: 265px;
  position: absolute;
  left: 23%;
  top: 23%;
  z-index: 100;
  box-shadow: 0px 0px 55px #000;
  background-color: #b6b6b6;
  border: 15px solid #ece7ee;
  border-radius: 50%;
  }

h1 {
  margin-top: 25px;
  text-align: center;
  font: 60px 'Lobster', cursive;
}

.control {
  display: inline-block;  
  margin-top: -60px;
  height: 60px;
  width: 60px;
}

.control:nth-child(2){  
  margin: -20px 20px 20px 65px;
}

.btn { 
  margin: 0px 12.7px 0px 12.7px;
  width: 30px;  
  height: 30px;
  border-radius: 50%;
  border: 2px solid #272725; 
  cursor: pointer;
  background: #ffff00;
  box-shadow: 0px 2px 6px #000;
}

.btn:active {
  box-shadow: 0px 0px 0px #000;
}
.start {
  background: #ff0000;
}

h3 {
  margin-top: 5px;
  font: 11px 'Oswald';
  text-align: center; 
}

#bulb {
  position: absolute;
  left: 189px;
  top: 107px;
  width: 8px;  
  height: 8px;
  background: #32050c;
  border: 2px solid #272725; 
  border-radius: 50%;    
}

#screen {
  width: 65px;  
  height: 35px;
  background: #1d1d1d;
  border: 2px solid #ece7ee;
  border-radius: 5px;
  margin: -9px auto 0px;
  text-align: center;  
  font: 35px 'VT323', cursive;
  color: #f08b48;
}

.square {    
  float: left;
  width: 245px;  
  height: 245px;  
  border: 5px solid #ece7ee;
  margin: 10px;
  box-shadow:
		inset 0 0 3px 1px rgba(0,0,0,.8),
		inset rgba(0,0,0,.3) -5px -5px 8px 5px,
		inset rgba(255,255,255,.5) 5px 5px 8px 5px,
		1px 1px 1px rgba(255,255,255,.1),
		-2px -2px 5px rgba(0,0,0,.5);
}

.green {
  background: linear-gradient(to bottom right, green, #00FF00);
  border-radius: 100% 5% 0 5%;
}

.activeGreen {
  background: #00e600;
  	box-shadow:
		inset 0 0 5px 3px rgba(0,0,0,.8),
		inset rgba(0,0,0,.3) -5px -5px 8px 5px,
		inset rgba(255,255,255,.5) 5px 5px 8px 5px,
		1px 1px 1px rgba(255,255,255,.2),
		-2px -2px 5px rgba(0,0,0,.5);
}

.red {
  background: linear-gradient(to bottom left, red, #e60000);
  border-radius: 5% 100% 5% 0;  
}

.activeRed {
  background: #FF7979;
  	box-shadow:
		inset 0 0 5px 3px rgba(0,0,0,.8),
		inset rgba(0,0,0,.3) -5px -5px 8px 5px,
		inset rgba(255,255,255,.5) 5px 5px 8px 5px,
		1px 1px 1px rgba(255,255,255,.2),
		-2px -2px 5px rgba(0,0,0,.5);
}

.yellow {
  background: linear-gradient(to top right, yellow, rgb(255, 255, 10));
  border-radius: 5% 0 5% 100%;  
}

.activeYellow {
  background: #FFFF95;
  	box-shadow:
		inset 0 0 5px 3px rgba(0,0,0,.8),
		inset rgba(0,0,0,.3) -5px -5px 8px 5px,
		inset rgba(255,255,255,.5) 5px 5px 8px 5px,
		1px 1px 1px rgba(255,255,255,.2),
		-2px -2px 5px rgba(0,0,0,.5);
}

.blue {
  background: linear-gradient(to top left, blue, #A6A6FF);
  border-radius: 0 5% 100% 5%;
}

.activeBlue {
  background: #0096ff;
  	box-shadow:
		inset 0 0 5px 3px rgba(0,0,0,.8),
		inset rgba(0,0,0,.3) -5px -5px 8px 5px,
		inset rgba(255,255,255,.5) 5px 5px 8px 5px,
		1px 1px 1px rgba(255,255,255,.2),
		-2px -2px 5px rgba(0,0,0,.5);
}
              
            
!

JS

              
                // ==== MODEL ====
function MakeButton(btn, cls) {
  this.btn = btn; 
  this.cls = cls;
}

var btns = [new MakeButton(".green", "activeGreen"),
            new MakeButton(".red", "activeRed"),
            new MakeButton(".yellow", "activeYellow"),
            new MakeButton(".blue", "activeBlue")];

var sounds = ["sound1", "sound2", "sound3", "sound4", "error", "victory"];

var randomSequence = [],
    playerSequence = [],
    count = 0,
    strict = false,
    game = false;

function highlightBtn(id) {
  $(btns[id].btn).addClass(btns[id].cls);
      setTimeout(function(){ //wait some time and make background color as it was
      $(btns[id].btn).removeClass(btns[id].cls);
      }, 300);
}

function playSound(id) { 
  $("#" + sounds[id])[0].play(); 
}//.get(0).cloneNode().play();

function playSequence() {
  $(".square").css("pointer-events", "none"); //disable colored buttons
  $("#screen").text(count < 10 ? "0" + count : count); //add zero when necessary  
       var i = 0;
       var interval = setInterval(function() {
        playSound(randomSequence[i]);
        highlightBtn(randomSequence[i]); 
        i++;
        if (i >= randomSequence.length) {
            clearInterval(interval);
            $(".square").css("pointer-events", "auto"); //enable colored buttons
        }
     }, 600);     
  
  playerSequence = []; //clear player input  
}

function randomGenerator() {
    count++; // update current round    
    randomSequence.push(Math.floor(Math.random() * 4));  
    playSequence();
}

//===== MEDIATOR ====
function start() {
  game = game === false ? true : false;
  if (game) {
    randomGenerator(); 
  } else { //if pressed START when game is running
    reset(); //just    
  }
}

function strictHandler() {
  strict = strict === true ? false : true; 
  if (strict) {
     $("#bulb").css("background-color", "#f30a0a"); //light on
  } else {
     $("#bulb").css("background-color", "#32050c");  //light off
  }
}

function reset() {
    randomSequence = [];
    playerSequence = [];
    count = 0;
    strict = false;
    game = false;
    $("#screen").text("--");
}
  
function checkPlayerInput(id) {
  if(game) { //only if was pressed Start     
     playerSequence.push(parseInt(id, 10)); //string into number
     highlightBtn(id);
    
  for (var i = 0; i < playerSequence.length; i++) {
   if (randomSequence[i] !== playerSequence[i]) {
      $("#screen").text("!!");
      playSound(4); // error sound
           setTimeout(function() {// wait 2 sec, then reset or repeat seqence
            if (strict) {             
               reset();                            
            }
            else {
               playerSequence.pop(); //remove last wrong number           
               playSequence();                 
            }
          }, 2000);  
    } else {
       playSound(id); //if reached here, play good sound  
    }
   }
    if (playerSequence.length === 20) {
       setTimeout(function() { //if player repeated right 20 times in a row
          $("#screen").text("WIN");
          playSound(5);
          setTimeout(function(){ 
          reset();
          }, 4000);
       }, 1000);  
     }
    
     else if (randomSequence.length === playerSequence.length) {
       setTimeout(function() { //wait 1sec then repeat sequence and add new btn
       randomGenerator();
       }, 1000);  
     }
  } 
}
//===== MEDIATOR'S END ====

// ==== VIEW ====

$('div').on('click', function() {
  
  if ($(this).is(".start")) {
    start();
  }
  
  if ($(this).is( ".strict" )) {
   strictHandler();   
  }
  
  if ($(this).is(".green, .red, .yellow, .blue")) {
     checkPlayerInput(event.target.id);
  }
});


/* 
//==============================
//WARNING: THE SAME LOGIC BELOW
//==============================
//only ONE global variable, with some properties and methods


var SG = {
  btns: [{ color: ".green", active: "activeGreen" },
         { color: ".red", active: "activeRed" },
         { color: ".yellow", active: "activeYellow" },
         { color: ".blue", active: "activeBlue" }], 
  
  sounds: ["sound1", "sound2", "sound3", "sound4", "error", "victory"],
  
  randomSequence: [],
  playerSequence: [],
  count: 0,
  strict: false,
  game: false
};

SG.highlightBtn = function(id) {
  $(SG.btns[id].color).addClass(SG.btns[id].active);
      setTimeout(function(){ //wait some time and make background color as it was
      $(SG.btns[id].color).removeClass(SG.btns[id].active);
      }, 300);
}

SG.playSound = function(id) { 
  $("#" + SG.sounds[id])[0].play(); 
}

//here and down

SG.playSequence = function() {
  $(".square").css("pointer-events", "none"); //disable colored buttons
  $("#screen").text(SG.count < 10 ? "0" + SG.count : SG.count); //zeropad 
       var i = 0;
       var interval = setInterval(function() {
        SG.playSound(SG.randomSequence[i]);
        SG.highlightBtn(SG.randomSequence[i]); 
        i++;
        if (i >= SG.randomSequence.length) {
            clearInterval(interval);
            $(".square").css("pointer-events", "auto"); //enable colored buttons
        }
     }, 600);     
  
  SG.playerSequence = []; //clear player input  
}

SG.randomGenerator = function() {
    SG.count = SG.count + 1; // update current round    
    SG.randomSequence.push(Math.floor(Math.random() * 4));  
    SG.playSequence();
}

//===== MEDIATOR ====
SG.start = function() {
  if (SG.game === false) {
    SG.randomGenerator(); 
    SG.game = true;
  } else { //if pressed START when game is running
    SG.reset(); //just    
    SG.game = false;
  }
}

SG.strictHandler = function() {
  if (SG.strict === false) {
     $("#bulb").css("background-color", "#f30a0a"); //light on
     SG.strict = true;
  } else {
     $("#bulb").css("background-color", "#32050c");  //light off
     SG.strict = false;
  }
}

SG.reset = function() {
    SG.randomSequence = [];
    SG.playerSequence = [];
    SG.count = 0;
    SG.strict = false;
    SG.game = false;
    $("#screen").text("--");
}
  
SG.checkPlayerInput = function(id) {
  if(SG.game === true) { //only if was pressed Start     
     SG.playerSequence.push(parseInt(id, 10)); //string into number
     SG.highlightBtn(id);
    
  for (var i = 0; i < SG.playerSequence.length; i++) {
   if (SG.randomSequence[i] !== SG.playerSequence[i]) {
      $("#screen").text("!!");
      SG.playSound(4); // error sound
           setTimeout(function() {// wait 2 sec, then reset or repeat seqence
            if (SG.strict === true) {             
               SG.reset();                            
            }
            else {
               SG.playerSequence.pop(); //remove last wrong number           
               SG.playSequence();                 
            }
          }, 2000);  
    } else {
       SG.playSound(id); //if reached here, play good sound  
    }
   }
    if (SG.playerSequence.length === 20) {
       setTimeout(function() { //if player repeated right 20 times in a row
          $("#screen").text("WIN");
          SG.playSound(5);
          setTimeout(function(){ 
          SG.reset();
          }, 4000);
       }, 1000);  
     }
    
     else if (SG.randomSequence.length === SG.playerSequence.length) {
       setTimeout(function() { //wait 1sec then repeat sequence and add new btn
       SG.randomGenerator();
       }, 1000);  
     }
  } 
}
//===== MEDIATOR'S END ====

// ==== VIEW ====

$('div').on('click', function() {
  
  if ($(this).is(".start")) {
    SG.start();
  }
  
  if ($(this).is( ".strict" )) {
   SG.strictHandler();   
  }
  
  if ($(this).is(".green, .red, .yellow, .blue")) {
   SG.checkPlayerInput(event.target.id);
  }
});

*/
              
            
!
999px

Console