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

            
              <body class="text-center bkg">
  <div class="container-fluid">
  <h3 id="strictMode">Strict Mode is Off</h3>
  </div>
    <div class="container-fluid">
        <button class="btn btn-info" onClick="start()">START</button>
        <button class="btn btn-info" onClick="reset()">RESET</button>
        <button class="btn btn-info" onClick="strictFun(this)">Strict Mode</button>
      </div>
       <div class="container-fluid">
       <h2 id="messg" ></h2>
      </div>
      <br>
      <div id="boxes" class="container-fluid">
        <canvas id="greenC" onClick="clickBox(this)">
      </canvas>
        <canvas id="yellowC" onClick="clickBox(this)">
      </canvas>
        <br>
        <canvas id="redC" onClick="clickBox(this)">
      </canvas>
        <canvas id="blueC" onClick="clickBox(this)">
      </canvas>
      </div>
      <div class="container-fluid" id="spiegazioni">
      <h1 id="x" class="hidden">combinations =</h1>
      <h1 id="z" class="hidden">guesses =</h1>
      <h1 id="timez">Round</h1>
      </div>

</body>
            
          
!

CSS

            
              .bkg {
  background-color: #E1EFF6;
}
#greenC {
    background-color:#50ed38;
    width:150px;
    height:150px;
    border:1px solid black;
    border-top-left-radius: 100%;
  }
#yellowC {
    background-color:yellow;
    width:150px;
    height:150px;
    border:1px solid black;
    border-top-right-radius: 100%;
  }
#redC {
    background-color:#BA1B1D;
    width:150px;
    height:150px;
    border:1px solid black;
    border-bottom-left-radius: 100%;
  }
#blueC {
    background-color:blue;
    width:150px;
    height:150px;
    border:1px solid black;
    border-bottom-right-radius: 100%;
    
  }
  #strictMode {
    padding-top: 1%;
  }
  #spiegazioni {
    padding-top: 2%;
  }
  #boxes {
   padding-top: 1%;
  }
.hidden {
  display:none;
}
            
          
!

JS

            
              var greenBox = document.getElementById("greenC");
var yellowBox = document.getElementById("yellowC");
var redBox = document.getElementById("redC");
var blueBox = document.getElementById("blueC");
var combinations = [];
var guesses = [];
var actual = [];
var len;
var ss;
var strictVal = 0;

//suoni
var greenSound = new Audio("https://res.cloudinary.com/dwfodxlfi/video/upload/v1523558319/sound1.wav");
var yellowSound = new Audio("https://res.cloudinary.com/dwfodxlfi/video/upload/v1523558320/sound2.wav");
var redSound = new Audio("https://res.cloudinary.com/dwfodxlfi/video/upload/v1523695555/179022__smartwentcody__ripping-paper-short.wav");
var blueSound = new Audio("https://res.cloudinary.com/dwfodxlfi/video/upload/v1523695918/wwww.wav");
//arrays
var boxes = [greenBox,yellowBox,redBox,blueBox];
var sounds = [greenSound,yellowSound,redSound,blueSound];
var counter = 0;
var round = 0;


//functions
var pushRandom = function(){
  //  make a box sound and glow and call backtonorm()
  combinations.push(Math.floor(Math.random()*4));
  boxes[combinations[combinations.length-1]].style.width="175px";
  boxes[combinations[combinations.length-1]].style.height="175px";
  sounds[combinations[combinations.length - 1]].play();
  setTimeout(function(){backNormal(boxes[combinations[combinations.length - 1]])},250);
  document.getElementById("x").textContent = "combinations = " + combinations;
};

var start = function(){
  counter++;
  round++;
  
  if (combinations.length < counter){
    pushRandom();
  }

  document.getElementById("x").textContent = "combinations = " + combinations;
  document.getElementById("timez").textContent = "Round " + round;
  console.log("combinations = " + combinations);
  console.log("guesses = " + guesses);
  console.log("counter = " + counter);
};

var backNormal = function(x){
  x.style.width="150px";
  x.style.height="150px";
};

var biggify = function(y){
  y.style.width = "165px";
  y.style.height = "165px";
}

var reset =function(){
  combinations = [];
  guesses = [];
  round = 0;
  document.getElementById("x").textContent = "combinations = " + combinations;
  document.getElementById("z").textContent = "guesses = " + guesses;
  document.getElementById("timez").textContent = "Round " + round;
};

var clickBox = function(box){
  
   if(box.id === "greenC"){
     guesses.push(0);
     greenSound.play();
     biggify(greenBox);
     setTimeout(function(){backNormal(greenBox)},250);

   }else if(box.id === "yellowC"){
     guesses.push(1);
     yellowSound.play();
     biggify(yellowBox);
     setTimeout(function(){backNormal(yellowBox)},250);
   }else if(box.id === "redC"){
     guesses.push(2);
     redSound.play();
     biggify(redBox);
     setTimeout(function(){backNormal(redBox)},250);
   }else if(box.id === "blueC"){
     guesses.push(3);
     blueSound.play();
     biggify(blueBox);
     setTimeout(function(){backNormal(blueBox)},250);
   }
  document.getElementById("z").textContent = "guesses = " + guesses;

  if(combinations.length === guesses.length && checkArs(combinations,guesses) === false && strictVal === 0){
    document.getElementById("messg").textContent = "Error! Retry.";
    console.log("actual = " + actual)
    guesses = [];
    actual = [];
    document.getElementById("z").textContent = "guesses = " + guesses;
    for(var i = 0;i<combinations.length;i++){
      actual.push(combinations[i]);
    }
    combinations =[];
    setTimeout(function(){provaErr()},3000);
    setTimeout(function(){
      document.getElementById("messg").textContent = "";
    },3000)

  }else if(combinations.length === guesses.length && checkArs(combinations,guesses) === false && strictVal === 1){
    setTimeout(function(){alert("Game Over. Press Start to play again.")},500);
    reset();
    round = 0;
    document.getElementById("timez").textContent = "Round " + round;
  }else if(checkArs(combinations,guesses) && round === 20){
    alert("Congratulations! You Won!")
    combinations = [];
    guesses = [];
    round = 0;
    document.getElementById("x").textContent = "combinations = " + combinations;
    document.getElementById("z").textContent = "guesses = " + guesses;
    document.getElementById("timez").textContent = "Round " + round;
  }else if (checkArs(combinations,guesses) === true){
    console.log("looks like they are identical")
    round++;
    setTimeout(function(){document.getElementById("timez").textContent = "Round " + round;},600);
    for(var i = 0;i<combinations.length;i++){
      actual.push(combinations[i]);
    }
    console.log("actual is now " + actual);
    combinations = [];
     guesses = [];
     document.getElementById("x").textContent = "combinations = " + combinations;
     document.getElementById("z").textContent = "guesses = " + guesses;
    setTimeout(function(){prova()},1000);    
};
}

var prova = function(){
  len = actual.length;
    if(len > 0){
      ss = actual.shift();
      console.log("tolgo da actual = " + ss);
      setTimeout(function(){
        biggify(boxes[ss]);
        sounds[ss].play()
        console.log("playing " + ss);
        combinations.push(ss);
        document.getElementById("x").textContent = "combinations = " + combinations;
        document.getElementById("z").textContent = "guesses = " + guesses;
        setTimeout(function(){backNormal(boxes[ss])},250);
      },790);  
      setTimeout(prova,1100);
    }else if(len ===0){
      setTimeout(function(){pushRandom()},900);
      document.getElementById("x").textContent = "combinations = " + combinations;
      document.getElementById("z").textContent = "guesses = " + guesses;
      return
    }
    
};

var provaErr = function(){
  len = actual.length;
    if(len > 0){
      rr = actual.shift();
      setTimeout(function(){
        console.log("tolgo da actual = " + rr);
        biggify(boxes[rr]);
        setTimeout(function(){backNormal(boxes[rr])},250);
        sounds[rr].play()
        console.log("playing " + rr);
        combinations.push(rr);
        document.getElementById("x").textContent = "combinations = " + combinations;
        document.getElementById("z").textContent = "guesses = " + guesses;
      },790);  
      setTimeout(provaErr,1100);
    }else if(len ===0){
      
      // document.getElementById("x").textContent = "combinations = " + combinations;
      // document.getElementById("z").textContent = "guesses = " + guesses;
      return
    }
}


var checkArs = function(arr1,arr2){
 if(JSON.stringify(arr1) === JSON.stringify(arr2)){
   return true;
 }else {
   return false;
 }
}

var strictFun = function(but){
  if(strictVal === 0){
    document.getElementById("strictMode").textContent = "Strict Mode is On";
    strictVal = 1;
    but.className = "btn btn-danger";
  }else {
    document.getElementById("strictMode").textContent = "Strict Mode is Off";
    strictVal = 0;
    but.className = "btn btn-info";
  }
}
            
          
!
999px

Console