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="win" class="hide">
  <p>Congratulations ! You won !</p>
</div>

<div id="playArea">
  <div id="button1" class="clickTile">
  </div>
  <div id="button2" class="clickTile">
  </div>
  <div id="button3" class="clickTile">
  </div>
  <div id="button4" class="clickTile">
  </div>
  
  <div id="control">
    
    <div>
      <input id="start" type="button" value="START">
    </div>
    <div id="strict">
     <input type="button" value="Strict mode"><span id="strictMode">Off</span>
    </div>
    <div id="count">
      <span>0</span>
    </div>
    </div>
</div>

            
          
!

CSS

            
              *{font-family : arial;}
body{ width : 100%; height : 100%; overflow-x : hidden; margin : 0; padding : 0; }
#playArea{
  margin : 10px auto;
  width : 400px; height : 400px;
  overflow: hidden; 
  border-radius : 50%;
  border : solid 10px #333;
  position : relative;
  /*box-sizing : border-box;
*/}
.clickTile{
  width : 250px; height : 250px; 
  background-color : #000; position : absolute;
  border : solid 5px #333; box-sizing: border-box;
}
#button1{background-color : #03A64D;/*#05fa73*/
  left : -50px;  top : -50px;} 
.button1{background-color : #05fa73 !important;}
#button2{background-color : #9C131A;/*#e31c26*/
right : -50px; top : -50px;} 
.button2{background-color : #e6333c !important;}
#button3{background-color : #CBA80C;/*#f1c70e*/
bottom : -50px; left : -50px;} 
.button3{background-color : #f2cd26 !important;}
#button4{background-color : #1E8DFF;/*#66b3ff*/
bottom : -50px; right : -50px;} 
.button4{background-color : #66b3ff !important;}

#control{
  position : absolute; 
  left : 50%; top : 50%;
  height : 200px; width : 200px; 
  margin-left : -100px;
  margin-top : -100px;
  background-color : #ccc;
  border-radius : 50%; overflow: hidden;
  border : 10px solid #333;
  text-align : center; 
  padding-top : 20px;
  box-sizing : border-box;
}
#control div{
  margin-bottom : 10px;
}
#control #start{
  width : 60px; height : 60px; 
  background-color : #f00; color : #fff; 
  border : none; 
  border-radius : 50%; 
  cursor : pointer; 
  box-sizing : border-box;
}
#control #strict input{
  margin-right : 10px;
  border : solid 1px #333; 
  background-color : #ff0;
  cursor : pointer; 
  border-radius : 3px; 
}
#control #strictMode{
  color : #222;
}
#control #count{
  position : absolute; bottom : 10px; left : 50%; margin-left : -20px;
  text-align : right;
  width : 40px; height : 40px; 
  background-color : #111; color : #f00;
  padding : 8px 9px; 
  box-sizing : border-box;
  font-size : 20px; 
  border-radius : 3px; 
}

#win{
  position : absolute; top : 50%; margin-top : -50px;
  height : 100px; width : 100%;
  text-align : center; font-size : 30px;
  background-color : #fff; 
  border-top : solid 10px #0f0;
  border-bottom : solid 10px #0f0;
  z-index : 5;
  opacity : 0;
  transition : all 0.5s;
}
.hide{display : none;}

.pointer{cursor : pointer;}
.bad{background-color : #f00 !important;}
.good{background-color : #0f0 !important;}
            
          
!

JS

            
              /*
https://s3.amazonaws.com/freecodecamp/simonSound1.mp3
https://s3.amazonaws.com/freecodecamp/simonSound2.mp3
https://s3.amazonaws.com/freecodecamp/simonSound3.mp3
https://s3.amazonaws.com/freecodecamp/simonSound4.mp3
*/
var strict = false;
var winCount = 20;
var template = [];
var a1 = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound1.mp3");
var a2 = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound2.mp3");
var a3 = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound3.mp3");
var a4 = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound4.mp3");

$(document).ready(function(){
  $("#start").click(function(){begin(template);});
});

$("#strict input").click(function(){ 
    if(strict === false){
      $('#strictMode').html('On');
      strict = true;
    }else{
      $('#strictMode').html('Off');
      strict = false;
    }
  });

function begin(template){
  template = [];
  template = addToTemplate(template);
  var count = template.length;
  $("#count span").html(count);
  
    playTemplate(template, count, 0);
  
}
function addToTemplate(template){
  template.push(Math.floor((Math.random()*4)+1));
  return template;
}

function buzz(id){
  switch(id){
      case 1 : a1.play(); 
                $("#button1").addClass("button1"); 
                setTimeout(function(){$("#button1").removeClass("button1");}, 250); 
                break;
        case 2 : a2.play();  
                $("#button2").addClass("button2"); 
                setTimeout(function(){$("#button2").removeClass("button2");}, 250); 
                break;
        case 3 : a3.play();  
                $("#button3").addClass("button3"); 
                setTimeout(function(){$("#button3").removeClass("button3");}, 250); 
                break;
        case 4 : a4.play();  
                $("#button4").addClass("button4"); 
                setTimeout(function(){$("#button4").removeClass("button4");}, 250); 
                break;
        default : break;
           }
}

function playTemplate(template, count, id){
  $("#count span").html(count);
  setTimeout(function(){
    
    buzz(template[id]);
    id++;
    if (id<count){
      playTemplate(template, count, id);
    }
    else{
      playerTurn(template, 0);
    }
  }, 1000);
}

function playerTurn(template, idPlayer){
  var playerSeq=0;
  $(".clickTile").addClass('pointer');
  
  $(".clickTile").on("click",function(){
    switch(this.id){
        case "button1" : playerSeq = 1; break;
        case "button2" : playerSeq = 2; break;
        case "button3" : playerSeq = 3; break;
        case "button4" : playerSeq = 4; break;
        default : break;
                  }
    $(".clickTile").removeClass('pointer');
    $(".clickTile").off("click");
    buzz(playerSeq);
    console.log("idPlayer : "+idPlayer+";"+ template[idPlayer]+" ; "+playerSeq);
    if(template[idPlayer] == playerSeq){
      if(idPlayer == template.length-1){
        //if last one of template and good answer
                setTimeout(function(){$("#control").addClass("good");}, 250);
                setTimeout(function(){$("#control").removeClass("good");}, 750);
        
        if(template.length == winCount){
          win();
        }
        else{ //add to template, restart the sequence
          template = addToTemplate(template);
          playTemplate(template, template.length, 0);
        }
      }else{
        playerTurn(template, idPlayer+1); 
        
      }
      
    }
    else if(template[idPlayer] != playerSeq){//if error
                setTimeout(function(){$("#control").addClass("bad");}, 250);
                setTimeout(function(){$("#control").removeClass("bad");}, 750);
      if(strict === false){//restart sequence
        playTemplate(template, template.length, 0); 
        
      }
      else{//reinit everything
        begin(template);
        
      }
    }
    });
}

function win(){
  setTimeout(function(){$("#win").removeClass("hide"); $("#win").css("opacity", 1)}, 250);
  setTimeout(function(){$("#win").css("opacity", 0);}, 1250);
  setTimeout(function(){$("#win").addClass("hide");}, 1750);
      var tpl =[];
  setTimeout(function(){begin(tpl)}, 3000);
}
            
          
!
999px

Console