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 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

              
                <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 wrong! Start again<button id="show">Ok</button></div>
  <div id="fail">failed</div>
  <div id="text"><span class="small">  need:
    1panel animations/
    2why does console keep showing errors/
    3how to play lastSeq</span></div>
</body>
              
            
!

CSS

              
                body{
  background-color:black;  
}

#console {
  position:absolute;
  	margin: 0 10% ;
  height:800px;
  width:800px;
	position: absolute;
	border-radius: 50%;
}

#innerConsole {
 top: 50%;    
   left: 50%;
   margin: -250px 0px 0px -250px;
   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: 500px;
  width: 500px;
  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:110px;
  left:190px;
  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: 110px;
  left:85px;
  font-size:20px;
  color:white;
  border-radius:50%;
  border:3px solid grey;
}

#round{
  overflow:hidden;
  position:absolute;
  margin-left:28%;
  top:200px;
  padding:8px;
  text-align:center;
  width:150px;
  height:50px;
  color:black;
 font-weight:bold;
  border: 4px solid black;
  background-color:gray;
  border-radius:30%;
  font-size:20px;
  
}

#strict{
  padding: 2px;
  position:absolute;
  text-align:center;
  height:40px;
  width:55px;
  top:75%;
  left:40%;
  border-radius:50%;
  background-color:red;
  color:white;
  font-weight:bold;
  border:2px solid grey;
}
#strictLight{
  position:absolute;
top:78%;
  left:55%;
  height:10px;
  width:20px;
  border-radius:50%;
  border:2px solid grey;
  color:black;
    background-color:black;
}



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

}
h{
  color:black;
  margin:30% 15%;
  text-align:center;
  font-weight:bold;
  font-size:90px;
  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% 33%;
}
.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; }
} 

              
            
!

JS

              
                var pSeq = []; //PLAYERS Choices
var cSeq = []; //CPU choices
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).addClass('animate');
//   setTimeout(function(){
//       $("#"+panelId).removeClass('animate')},100);
  $("#"+panelId).css("background-color", "white");
  setTimeout(function(){
    $("#"+panelId).css("background-color","");
  });
  
  
  audioF[panelId.toLowerCase()].play();
 
  cpuTurn = 1;
 if (pSeq[pSeq.length - 1] !== cSeq[a] && strict % 2) {
    audioF['wrong'].play();
    pSeq = [];
    a = 0;
    wasRight = 0;
    setTimeout(function() {
      alert("Back To Round 1!");
      stopGame()
    }, 2000);
  }
  else  if (pSeq[pSeq.length - 1] !== cSeq[a]) {    $("#strictFail,fail").addClass("visible");

    audioF['wrong'].play();
    wasRight = 0;
    pSeq = [];
    a = 0;
    roundVal = cSeq.length;
    setTimeout(function() {
      lastSeq()
    }, 1000);

  } 
  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   
  }
 
});

//used to replay lastCpuSeq
function lastSeq() {
  for (var c = 0; c <= cSeq.length; c++) {
              
  var last=  setTimeout(function(){
               if(c>=cSeq.length){ clearInterval(last);
                                 return;} audioF[cSeq[c].toLowerCase()].play(); }, 1000);
                                 
  }
}

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

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

})

function cpuSeq() {
     if (cpuTurn > 0) { //count to stop cpu acting out of turn.
       $(".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;  }  
  //        $("#"+panelId).css("background-color", "white");
  // setTimeout(function(){
  //   $("#"+panelId).css("background-color","");},200);
        console.log('cSeq[i]', cSeq[i]);
        console.log({cSeq})
         $("#" + cSeq[i]).css("background-color", "white");
       setTimeout (function(){
         console.log({i})
          $("#" + cSeq[i-1]).css("background-color","");
       }, 5);

              audioF[cSeq[i].toLowerCase()].play(); //play choice from cSeq.
i++;       

         cpuTurn = 0;
         $(".panel").prop('disabled', false);
      }, 800);       
     
  } else {
    lastSeq();
    cpuTurn=0;
  }
}


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

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

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

$("#show").on("click", function(){
  $("#strictFail").toggleClass("visible");
})
$("#strict").on("click", function() {
  strict++;
  $("#strictLight").toggleClass("lit");

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


              
            
!
999px

Console