css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

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.

            
              <body>
  <div id ="console">
  <div id ="wrap">
    <div class="panel unclickable"id ="TL"></div>
    <div class="panel unclickable" id ="TR">
    </div>
  <div class="panel unclickable" id ="BR">
  </div>
  <div class="panel unclickable" id ="BL">
    </div>   
    <div id="innerConsole">
      <h>SIMON</h>
      <button class="button"id="start">Start!</button>
  <button id="stop">Reset!</button>
        <button id="strict">Strict!</button>
      <div id="strictLight"></div>
<!--               <button id="test">!</button>
 -->
 <div id="round">Round: </div>
    </div>
    </div>
    </div>
  <div id="strictFail">Oops!<br> Back to Round 1!<button class="show">Ok</button></div>
    <div id="win">You Win!<br> Well Done!<button class="show2">Ok</button></div>

  <div id="fail">Oops!<br> Try Again!<button class="show">Ok</button></div>

</body>
            
          
!
            
              body{
  background-color:black;  
}

#console {
  top: 50%;    
   left: 50%;
   margin: -330px 0px 0px -400px;
  height:800px;
  width:800px;
	position: absolute;
	border-radius: 50%;
}

#innerConsole {
 top: 50%;    
   left: 50%;
   margin: -200px 0px 0px -200px;
   position:absolute;
/*   this is how u centre in a div.
  position absolute makes it relative to outer div. 50 50% puts its corner inthe middle and then margin half o its size puts its center in the middle */
 background-color: white;
  border-radius: 50%;
  height: 400px;
  width: 400px;
  padding: 30px;
  overflow: hidden;
  border: 10px solid #333;
}



#wrap {
  background-color:grey;
   overflow: hidden;
	position: relative;
	width:800px; height: 500px;
border-radius:80%;
}

#stop{
  height:70px;
  width:78px;
  background-color:black;
 top:30%;
  left:35%;

  position:relative;
  font-size:20px;
  color:white;
  border-radius:50%;
  padding:1px;
    border:3px solid grey;

}
#start{
  height:70px;
  width:78px;
  background-color:black;
  position:relative; 
top:30%;
  left:20%;
  font-size:20px;
  color:white;
  border-radius:50%;
  border:3px solid grey;
}

#round{

  overflow:hidden;
  position:absolute;
top:45%;
  left:50%;
       margin: -25px 0px 0px -75px;

  padding:6px;
  text-align:center;
  width:155px;
  height:55px;
  color:black;
 font-weight:bold;
  border: 4px solid black;
  background-color:gray;
  border-radius:30%;
  font-size:25px;
  
}

#strict{
  padding: 2px;
  position:absolute;
  text-align:center;
  height:40px;
  width:55px;
  top:80%;
  left:38%;
  border-radius:50%;
  background-color:red;
  color:white;
  font-weight:bold;
  border:2px solid grey;

}
#strictLight{
  position:absolute;
top:84%;
  left:55%;
  height:10px;
  width:20px;
  border-radius:50%;
  border:2px solid grey;
 background: radial-gradient( grey 0%, lightblue 60%);
    background-color:black;
}



.panel{     
overflow:hidden;
  cursor:pointer;
  
}
.unclickable{
      pointer-events:none;

}
h{
  font-family:"impact";
  color:black;
  margin:30% 22%;
  text-align:center;
  font-weight:bold;
  font-size:70px;
  text-shadow:2px 2px silver;
}

#TR{
    border:2px solid black;
  position: absolute;
  background-color: red;
  width: 50%;
  height: 50%;
  left: 50%;
      border-top-right-radius: 170%;

  right: 0%;
  bottom: 50%;
  top: 0%;
    overlap:hidden;


}

#TL{
    border:2px solid black;
      border-top-left-radius: 100%;

    position: absolute;

  background-color: green;

  width: 50%;

  height: 50%;

  left: 0%;

  right: 45%;

  bottom: 50%;

  top: 0%;
    overlap:hidden;

}

#BL{  border:2px solid black;
      border-bottom-left-radius: 100%;
      position: absolute;
  background-color: yellow;
  width: 50%;
  height: 50%;
  left: 0%;
  right: 45%;
  bottom: 0%;
  top: 50%;
  overlap:hidden;
}

#BR{
  overflow:hidden;
  border:2px solid black;
    position: absolute;
      border-bottom-right-radius: 100%;
  background-color: blue;

  width: 50%;

  height: 50%;

  left: 50%;
  right: 1%;
  bottom: 0%;

  top: 50%;
}
.small{
  font-size:20px;
}
.visible{
  display: block !important;
}

#strictFail, #fail{
  opacity:1;
  position:absolute;
  display:none;
  text-align:center;
  height:250px;
  width:600px;
  margin:10% 18%;
  border:3px solid white;
  border-radius:10%;
  background-color:grey;
  color:black;
  font-weight:bold;
  font-size:40px;
  }



.show{
  border:2px solid black;
  border-radius:20%;
  margin:10% 45%;
}
.show2{
  border:2px solid black;
  border-radius:20%;
  margin:10% 45%;
}

#win{
  opacity:1;
  position:absolute;
  display:none;
  text-align:center;
  height:250px;
  width:600px;
  margin:10% 18%;
  border:3px solid white;
  border-radius:10%;
  background-color:grey;
  color:black;
  font-weight:bold;
  font-size:40px;
  
}
  
  
  
  
.lit{
 margin-top:-2%;
  border:3px dotted yellow !important;
  height:30px !important;
  width:38px !important;
 background: radial-gradient( red 0%,orange 90%)!important;
}


#text{float:right;
  text-size:20px;
  height:300px;
  width:300px;
   background-color:white;
  color:black;
}



.animate{
  
  animation: flash-animation linear 0.2s 1;}
  @keyframes flash-animation {  
    0% {opacity:0.1; }
    50%   { opacity:0.9}
    100%{ opacity:1; }
} 

            
          
!
            
              var pSeq = []; //PLAYERS Choices
var cSeq = []; //CPU choices
var lastCpu=[];
var choices = ["TL", "TR", "BL", "BR"];
var seq; //name of 1 choice 
var roundVal = 1; //counter of rounds 
var audioF = {
  'tl': new Audio("https://s3.amazonaws.com/freecodecamp/simonSound1.mp3"),
  'tr': new Audio("https://s3.amazonaws.com/freecodecamp/simonSound2.mp3"),
  'bl': new Audio("https://s3.amazonaws.com/freecodecamp/simonSound3.mp3"),
  'br': new Audio("https://s3.amazonaws.com/freecodecamp/simonSound4.mp3"),
  'wrong': new Audio("http://cstrike.csmegagaming.com/sound/misc/no.wav"),
}
var cpuTurn = 1; //count for cpuTurn
var ind = [Math.floor(Math.random() * choices.length)];
var interval;
var count = 0;
var wasRight = 1; //var that sees if last user seq was right or wrong
var a = 0; //used in forloop for CSeq
var strict = 2; //used to see if strict mode on.it increments by 1 each press so we divide by 2 to see if odd or even
var cpuWorking;

$(".panel").on("click", function() {
   var panelId = $(this).attr("id");
  $("#"+panelId).css("background-color", "white");
  setTimeout(function(){
    $("#"+panelId).css("background-color","");},200);
  
  
  audioF[panelId.toLowerCase()].play();
 
  cpuTurn = 1;
  pSeq.push(panelId); console.log(pSeq,cSeq);
 if (pSeq[pSeq.length - 1] !== cSeq[a] && strict % 2) {
    audioF['wrong'].play();
   $("#strictFail").addClass("visible");
    console.log('strict wrong');//STRICT MODE
    pSeq = [];
    a = 0;
    wasRight = 0;
    setTimeout(function() {
      stopGame()
    }, 2000);
  }
  else  if (pSeq[pSeq.length - 1] !== cSeq[a]) {    

    audioF['wrong'].play();
    $("#fail").addClass("visible");
    wasRight = 0;
    pSeq = [];
    a = 0;
    roundVal = cSeq.length;
    // setTimeout(function() {
    //   lastSeq()
    // }, 1000);

    console.log("wrong no strict");
  } 
  else {
    a++; 
    wasRight=1;
  }if (pSeq.length === cSeq.length && wasRight == 1) {
    pSeq = [];
        $("#round").addClass('animate');
 roundVal++;
    $("#round").html("Round: " + roundVal);
    a = 0;
    setTimeout(function(){
      $("#round").removeClass('animate')},200);
    setTimeout(function() {
      cpuSeq()
    }, 1000);
    // so we move on to the next round   
  }
 
});

function cpuSeq() {
  if(roundVal>=21){
    $("#win").addClass("visible");
    stopGame();
  }
     if (cpuTurn > 0) { //count to stop cpu acting out of turn.
       lastCpu=[];
       $(".panel").prop('disabled', true);
    cSeq.push(newChoice()); //get random choice into cSeq aray
    var i=0;
     window.start = setInterval(function() {
         if(i>=cSeq.length){
           clearInterval(window.start);
       return;  }  

       var current=  cSeq[i];//store var so it holds i value
         $("#" + current).css("background-color", "white", "border", "3px dotted white");
       setTimeout (function(){
          $("#" + current).css("background-color","");},300);

              audioF[cSeq[i].toLowerCase()].play(); //play choice from cSeq.
lastCpu.push(cSeq[i]);
i++;       
         cpuTurn = 0;
         $(".panel").prop('disabled', false);
      }, 700);       
     
        console.log(cSeq + cSeq.length, "player moves = ", pSeq);
  } else {
    cpuTurn=0;
  }
}

function lastSeq() {
  //Looks at lastCpu moves array and iterates through playing each note...     

  for (var c = 0; c <= lastCpu.length; c++) {
    (function(local){ 
       var note = lastCpu[local];
 setTimeout(function(){
        console.log(lastCpu, "Playing: ", [note.toLowerCase()]);
         $("#" + note).css("background-color", "white");
       setTimeout (function(){
          $("#" + note).css("background-color","");},05);
        audioF[note.toLowerCase()].play();
      }, 800 * local); // * localmeans fire every 1000 by locals iterations... so however long local takes +1500.
      
    }(c)); // this calls the function from c
  }
}




// $("#test").on("click", function() {
//   lastSeq();
// })

$("#start").on("click", function() {
  $(".unclickable").css({
    'pointer-events': 'auto'
  });
  cpuSeq();

})

$("#stop").on("click", function() {
  stopGame();
})

function stopGame() {
  console.log("Stopped",cSeq,pSeq)
  cSeq = [];
  pSeq = [];
  roundVal = 1;
  cpuTurn = 1;
  lastCpu=[];
  
  $("#round").html("Round: " + roundVal);
  $(".unclickable").css({
    'pointer-events': 'none'
  });
}



function newChoice() {
  ind = [Math.floor(Math.random() * choices.length)];
  seq = choices[ind];
  return seq;
}

//NOW TRIGGERS LASTSEQ
$(".show").on("click", function(){
  $("#strictFail").removeClass("visible");
  $("#fail").removeClass("visible");
 if (strict % 2==0){
   lastSeq();}
})

$("#strict").on("click", function() {
  console.log("pressed strict");
  strict++;
  $("#strictLight").toggleClass("lit");

});
$("#round").html("Round: " + roundVal);

$(".show2").on("click", function(){
  $("#win").removeClass("visible")});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console