cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

            
              <link href="https://fonts.googleapis.com/css?family=Press+Start+2P" rel="stylesheet">

<div class="wrapper">
  <audio id="audio5" src="http://res.cloudinary.com/mdrisk/video/upload/v1510621781/beep2_riklau.mp3" ></audio>
  <div id = "leftTop" class = "touch" onClick="touched(this.id)"><audio id="audio1" src="https://s3.amazonaws.com/freecodecamp/simonSound1.mp3" ></audio>
  </div>
  <div id = "leftBottom" class = "touch" onClick="touched(this.id)"><audio id="audio2" src="https://s3.amazonaws.com/freecodecamp/simonSound2.mp3" ></audio>
  </div>
  <div id = "rightBottom" class = "touch" onClick="touched(this.id)"><audio id="audio3" src="https://s3.amazonaws.com/freecodecamp/simonSound3.mp3" ></audio>
  </div>
  <div id = "rightTop" class = "touch" onClick="touched(this.id)"><audio id="audio4" src="https://s3.amazonaws.com/freecodecamp/simonSound4.mp3" ></audio>
  </div>
  <div id = "cnter" class = "touch">
    <div id = ctr_top class="touch">Simon</div>
    <div id = ctr_mid_left class="touch">Score<p id="score">00</p></div>
    <div id = ctr_mid_ctr class="touch" onClick="touched(this.id)">Start</div>
    <div id = ctr_mid_right class="touch">Strict<br><button id = "strictIndicator" onClick="strIndicator()" class="button-red-unlit"></button></div>
    <div id = ctr_bottom class="touch" onClick="touched(this.id)"><p id="battery">On</p></div>
  </div>
  
  </div>

<div id="winModal" class="modal">
  <!-- Modal content -->
  <div class="modal-content">
    <span class="close">&times;</span>
    <p>You Win!</p>
    <button onClick="newGame()">Play Again?</button>
    <button onClick="closeWindow()">Cancel</button>
  </div>

</div>
            
          
!
            
              body, html{
  height:100%;
  width:100%;
  display:flex;
  flex-flow:column;
  justify-content:center;
  align-items:center;
  font-family: 'Press Start 2P', cursive;
}

/* -- Classes -- */

.wrapper{
  display:grid;
  grid-template-columns:1fr, 2fr, 2fr, 1fr;
  grid-template-rows:1fr, 2fr, 2fr, 1fr;
  grid-template-areas:
    "leftTop   .     .     rightTop"
    "leftTop cnter cnter rightTop"
    "leftBottom cnter cnter rightBottom"
    "leftBottom   .     .     rightBottom";
  width:70%;
  height:60%;
  max-width:500px;
  min-width:300px;
  border: 2px solid #FFF; 
  border-radius: 5%; 
}
.touch{
  background: #000;
  border: 5px solid #FFF;
  border-radius: 5%;
}
.touch:hover{
  cursor:pointer;
}
/* The Modal (background) */
.modal {
    display: none; 
    position: fixed;
    z-index: 1; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    overflow: auto; /
    background-color: rgb(0,0,0); 
    background-color: rgba(0,0,0,0.4);
}
/* Modal Content/Box */
.modal-content {
    background-color: #fefefe;
    margin: 15% auto; /* 15% from the top and centered */
    padding: 20px;
    border: 1px solid #888;
    width: 150px; 
}

/* The Close Button */
.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}
.close:hover,
.close:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

/* -- IDs -- */
#battery {
  padding:0px;
  margin:0px;
}
#leftTop {
  grid-area: leftTop;
  grid-row: 1 / 3;
  grid-column: 1 / 3;
  background-color: #0A0;
}
#rightTop {
  grid-area: rightTop;
  grid-row: 1 / 3;
  grid-column: 3 / 5;
  background-color: #A00;
}
#rightBottom {
  grid-area: rightBottom;
  grid-row: 3 / 5;
  grid-column: 3 / 5;
  background-color:#003F87;
}
#leftBottom {
  grid-area: leftBottom;
  grid-row: 3 / 5;
  grid-column: 1 / 3;
  background-color: #CC0;
}
#cnter {
  grid-area: cnter;
  grid-column: 2 / 4;
  grid-row:2/4;
  border-radius:50%;
  display:grid;
  grid-template-columns:1fr, 1fr;
  grid-template-rows:1fr, 1fr, 1fr;
  grid-template-areas:
    "title title "
    "leftmid rightmid"
    "bottommid midmid ";
  grid-gap: 2px; 
  justify-content:center;
  text-align:center;
  align-content:center;
}
#ctr_top {
  grid-area: title;
  grid-column: 1 / 4;
  font-size:32px;
  padding: 0px;
  background: #FFF;
}
#ctr_mid_right {
  grid-area: rightmid;
  padding: 0px;
  background: #FFF;
  cursor:default;
}
#ctr_mid_ctr {
  grid-area: midmid;
  padding: 0px;
  background: #FFF;
  align-self:center;
}
#ctr_mid_left {
  grid-area: leftmid;
  padding: 0px;
  background: #FFF;
}
#ctr_bottom {
  grid-area: bottommid;
  padding: 0px;
  background: #FFF;
}
#score {
  font-size:24px;
  padding:0;
  margin:0;    
}
/* -- Light Ups -- */
.button-red-unlit {
  margin: 0 auto;
  width: 24px;
  height: 24px;
  background-color: #A00;
  border-radius: 50%;
}
.button-red-lit:focus,
.button-red-unlit{outline:0;}
.button-red-lit {
  margin: 0 auto;
  width: 24px;
  height: 24px;
  background-color: #F00;
  border-radius: 50%;
  box-shadow: rgba(0, 0, 0, 0.2) 0 -1px 7px 1px, inset #304701 0 -1px 9px, #FF0000 0 2px 12px;
}
.button-red-lit:hover,
.button-red-unlit:hover{
  cursor: pointer;
}

.led-green {
  background-color: #0A0;
  -webkit-animation: blinkGreen 0.5s ;
  -moz-animation: blinkGreen 0.5s ;
  -ms-animation: blinkGreen 0.5s ;
  -o-animation: blinkGreen 0.5s ;
  animation: blinkGreen 0.5s ;
}

@-webkit-keyframes blinkGreen {
     from { background-color: #0A0; }
    50% { background-color: #0F0; }
    to { background-color: #0A0; }
}
@-moz-keyframes blinkGreen {
    from { background-color: #0A0; }
    50% { background-color: #0F0; }
    to { background-color: #0A0; }
}
@-ms-keyframes blinkGreen {
     from { background-color: #0A0; }
    50% { background-color: #0F0; }
    to { background-color: #0A0; }
}
@-o-keyframes blinkGreen {
     from { background-color: #0A0; }
    50% { background-color: #0F0; }
    to { background-color: #0A0; }
}
@keyframes blinkGreen {
     from { background-color: #0A0; }
    50% { background-color: #0F0; }
    to { background-color: #0A0; }
}

.led-red {
  background-color: #A00;
  -webkit-animation: blinkRed 0.5s ;
  -moz-animation: blinkRed 0.5s ;
  -ms-animation: blinkRed 0.5s ;
  -o-animation: blinkRed 0.5s ;
  animation: blinkRed 0.5s ;
}
@-webkit-keyframes blinkRed {
     from { background-color: #A00; }
    50% { background-color: #F00; }
    to { background-color: #A00; }
}
@-moz-keyframes blinkRed {
    from { background-color: #A00; }
    50% { background-color: #F00; }
    to { background-color: #A00; }
}
@-ms-keyframes blinkRed {
     from { background-color: #A00; }
    50% { background-color: #F00; }
    to { background-color: #A00; }
}
@-o-keyframes blinkRed {
     from { background-color: #A00; }
    50% { background-color: #F00; }
    to { background-color: #A00; }
}
@keyframes blinkRed {
     from { background-color: #A00; }
    50% { background-color: #F00; }
    to { background-color: #A00; }
}

/* Light blue - #0276FD, Dark blue - #003F87 */
.led-blue {
  background-color: #003F87;
  -webkit-animation: blinkBlue 0.5s ;
  -moz-animation: blinkBlue 0.5s ;
  -ms-animation: blinkBlue 0.5s ;
  -o-animation: blinkBlue 0.5s ;
  animation: blinkBlue 0.5s ;
}
@-webkit-keyframes blinkBlue {
     from { background-color: #003F87; }
    50% { background-color: #0276FD; }
    to { background-color: #003F87; }
}
@-moz-keyframes blinkBlue {
    from { background-color: #003F87; }
    50% { background-color: #0276FD; }
    to { background-color: #003F87; }
}
@-ms-keyframes blinkBlue {
     from { background-color: #003F87; }
    50% { background-color: #0276FD; }
    to { background-color: #003F87; }
}
@-o-keyframes blinkBlue {
     from { background-color: #003F87; }
    50% { background-color: #0276FD; }
    to { background-color: #003F87; }
}
@keyframes blinkBlue {
     from { background-color: #003F87; }
    50% { background-color: #0276FD; }
    to { background-color: #003F87; }
}
/* Light yellow - #FF0, Dark yellow - #CC0 */
.led-yellow {
  background-color: #CC0;
  -webkit-animation: blinkYellow 0.5s ;
  -moz-animation: blinkYellow 0.5s ;
  -ms-animation: blinkYellow 0.5s ;
  -o-animation: blinkYellow 0.5s ;
  animation: blinkYellow 0.5s ;
}
@-webkit-keyframes blinkYellow {
     from { background-color: #CC0; }
    50% { background-color: #FF0; }
    to { background-color: #CC0; }
}
@-moz-keyframes blinkYellow {
    from { background-color: #CC0; }
    50% { background-color: #FF0; }
    to { background-color: #CC0; }
}
@-ms-keyframes blinkYellow {
     from { background-color: #CC0; }
    50% { background-color: #FF0; }
    to { background-color: #CC0; }
}
@-o-keyframes blinkYellow {
     from { background-color: #CC0; }
    50% { background-color: #FF0; }
    to { background-color: #CC0; }
}
@keyframes blinkYellow {
     from { background-color: #CC0; }
    50% { background-color: #FF0; }
    to { background-color: #CC0; }
}
            
          
!
            
              var ai = [];
var player = [];
var aiTurn = true;
var playerTurn = false;
var index=0;
var match = 00;
var correct = true;
var on = false;
var battery = document.getElementById('battery');
var modal = document.getElementById('winModal');
var score = document.getElementById("score");
strict = false;

function touched(this_id){
  if(on){
  var item = document.getElementById(this_id);
  if(this_id == "leftTop"){   
    item.setAttribute("class","led-green touch");
    var audio = document.getElementById("audio2");
    audio.play();
    item.disabled = true;
    setTimeout(function() {
    item.setAttribute("class","touch");
    item.disabled = false;
    }, 500);
    if(playerTurn){
      //console.log("id = leftTop, playerTurn = true");
      player.push("leftTop");
      check();
    }
  }
else if(this_id == "rightTop"){   
    item.setAttribute("class","led-red touch");
    var audio = document.getElementById("audio3");
    audio.play();
    item.disabled = true;
    setTimeout(function() {
    item.setAttribute("class","touch");
    item.disabled = false;
    }, 500);
    if(playerTurn){
      //console.log("id = rightTop, playerTurn = true");
      player.push("rightTop");
      check();
    }
  }
else if(this_id == "rightBottom"){   
    item.setAttribute("class","led-blue touch");
    var audio = document.getElementById("audio4");
    audio.play();
    item.disabled = true;
    setTimeout(function() {
    item.setAttribute("class","touch");
    item.disabled = false;
    }, 500);
    if(playerTurn){
      //console.log("id = rightBottom, playerTurn = true");
      player.push("rightBottom");
      check();
    }
  }
  else if(this_id == "leftBottom"){   
    item.setAttribute("class","led-yellow touch");
    item.disabled = true;
    var audio = document.getElementById("audio1");
    audio.play();
    setTimeout(function() {
    item.setAttribute("class","touch");
    item.disabled = false;
    }, 500);
    if(playerTurn){
      //console.log("id = leftBottom, playerTurn = true");
      player.push("leftBottom");
      check();
    }
  }
  else if (this_id == "ctr_mid_ctr"){
    console.log("start");
    start();
  }
  }
  if (this_id == "ctr_bottom"){
    if(!on){
      on = true;
      battery.innerHTML = "Off";
    }
    else {
      on = false;
      battery.innerHTML = "On";
    }
  }
    
}
function replay(){
    index = 0;
    slowLoop();
}
function slowLoop(){
  touched(ai[index]);
  console.log("Slowloop index : "+index);
  index += 1;
  if(index < ai.length)
    setTimeout(slowLoop, 1000);
  else
    //console.log("end of replay");
    playerTurn = true;
    //index = 0;
}
function strIndicator(){
  console.log("strict method" + strict)
  var indicator = document.getElementById("strictIndicator");
  if(!strict){
    strict = true;
    indicator.setAttribute("class", "button-red-lit")}
  else{
    strict = false;
    indicator.setAttribute("class", "button-red-unlit")}
  reset();
}
function reset(){
  var id = window.setTimeout(function() {}, 0);
  while (id--) {
    window.clearTimeout(id); 
  }
  modal.style.display = "none";
  ai=[];
  match = 00;
  score.innerHTML = match;
  playerTurn = false;
  endplayer = true;
}
function newGame(){
  reset();
  setTimeout(function() {
    start();
  }, 2500);
}

function start(){
    player = [];
    var selection =Math.floor(Math.random() * 4) + 1 
    if(selection == 1)
      ai.push("leftTop");
    else if(selection == 2)
      ai.push("rightTop");
    else if(selection == 3)
      ai.push("rightBottom");
    else if(selection == 4)
      ai.push("leftBottom");
    console.log("end of start ");
    console.log("AI "+ ai);
    console.log("Player "+ player);
  replay();
}

function check(){
    //console.log("Start of Check");
    //console.log("AI "+ ai);
    //console.log("Player "+ player);
        
    for(var k = 0; k<player.length; k++){
      if (ai[k] != player[k]){
        console.log("No match");
        correct = false;
      } 
    }
      if(player.length == ai.length && correct){
        match +=1;
        score.innerHTML = match;
        if(match < 21){
        playerTurn = false;
        endplayer = true;
        setTimeout(function() {
        start();
        }, 2500);
        } else {
          winPopUp();
          console.log("You Win!");
        }
      } else if(!correct) {
        correct = true;
        player = [];
        playerTurn = false;
        var audio = document.getElementById("audio5");
        audio.play();
        if(strict){
          ai = [];
          match = 00;
          score.innerHTML = match;
          setTimeout(function() {
          start();
          }, 2500);
        } else {
        setTimeout(function() {
        replay();
        }, 2500);
        } 
      }
  console.log("end of check")
}


var span = document.getElementsByClassName("close")[0];
function winPopUp() {
    modal.style.display = "block";
}
span.onclick = function() {
    modal.style.display = "none";    
}
function closeWindow() {
   modal.style.display = "none";
}
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}

//To-Do AI, count matches, reset, strict, on/off
//var audio = document.getElementById("audio5");
    //audio.play();
            
          
!
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