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.

            
              <div class="wrapper-top">
            <div class="modal">
                <h2>CONGRATULATIONS</h2>
                <h3>YOU WON</h3>
            </div>
            <div class="top-left block" id="0">
                <audio class="top-left-audio" >
                    <source src="https://s3.amazonaws.com/freecodecamp/simonSound1.mp3" type="audio/mpeg">
                </audio>
            </div>
            <div class="top-right block" id="1">
                <audio class="top-right-audio" >
                    <source src="https://s3.amazonaws.com/freecodecamp/simonSound2.mp3" type="audio/mpeg">
                </audio>
            </div>
            <div id="outer-circle">
                <div id="inner-circle">
                    <div>
                        <h3 id="levelDisplay">00</h3> 
                        <h2 class="level-label">LEVEL</h2>
                    </div>  
                    <button id="start-btn">START</button>
                    <button id="strict-btn">STRICT</button>
                    <div id="outer-switch">
                       <div class="inner-switch"></div> 
                    </div>
                </div>
            </div>
        </div>    
            
        <div class="wrapper-bottom">    
            <div class="bottom-left block" id="2">
                <audio class="bottom-left-audio" >
                    <source src="https://s3.amazonaws.com/freecodecamp/simonSound3.mp3" type="audio/mpeg">
                </audio>
            </div>
            <div class="bottom-right block" id="3">
                <audio class="bottom-right-audio" >
                    <source src="https://s3.amazonaws.com/freecodecamp/simonSound4.mp3" type="audio/mpeg">
                </audio>
            </div>
        </div>

  <audio class="error">
        <source src="https://k003.kiwi6.com/hotlink/vsvciko2dz/DJ_Khaled_Another_One_Sound_Effect.mp3" type="audio/mpeg">
    </audio>
            
          
!
            
              
/*-------------------------- STYLE START ------------------------------*/
.wrapper-top{
	position: relative;
	background: white;
	text-align: center;
	margin-top: 10%;
}

.modal{
	margin: auto 30%;
	position: absolute;
	display: none;
	z-index: 500;
	height: 648px;
	width: 668px;
	background: #3596FF;
}

.modal h2{
	padding: 10%;
	font-size: 50px;
	margin-top: 40%;
}

.modal h3{
	font-size: 30px;
}

/*  TOP - LEFT  */
.top-left{
	background: #00743C;
	height: 300px;
	width: 300px;
	border-top-left-radius: 100px;
	position: relative;
	display: inline-block;
	box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
	border: 10px solid black;
}

/*  TOP - RIGHT  */
.top-right{
	background: #770000;
	height: 300px;
	width: 300px;
	/* border-top-right-radius: 40px; */
	position: relative;
	display: inline-block;
	box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
	border: 10px solid black;
}

/*  BOTTOM - LEFT  */
.bottom-left{
	background: #120074;
	height: 300px;
	width: 300px;
	position: relative;
	display: inline-block;
	box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
	border: 10px solid black;
}

/*  BOTTOM - RIGHT  */
.bottom-right{
	background: #B1BA00;
	height: 300px;
	width: 300px;
	border-bottom-right-radius: 100px;
	position: relative;
	display: inline-block;
	box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
	border: 10px solid black;
}


/* CIRCLE */
#outer-circle{
	background: black;
	height: 200px;
	width: 200px;
	border-radius: 100px;
	position: absolute;
	z-index: 100;
	margin: 0 50%; 
	transform: translate(-100px, -100px);
	box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

#inner-circle{
	height: 180px;
	width: 180px;
	background: white;
	border-radius: 100px;
	margin: 0 50%;
	transform: translate(-90px, 9px);
}

#inner-circle button{
	margin: 80px 0px;
	border: none;
}

#inner-circle button:nth-child(2){
	background: #57ED78;
	box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

#inner-circle button:nth-child(3){
	box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

.level-label{
	position: absolute;
	display: block;
	margin: auto;  
	padding-top: 20px;
	width: 55px;
	top: 0px;
	left: 62px;
}

#levelDisplay{
	width: 50px;
	border: 2px solid black;
	border-radius: 20px;
	position: absolute;
	margin: 40px 0px 0px 63px;
}

#outer-switch{
	height: 10px;
	width: 40px;
	border: 2px solid black;
	background: black;
	position: absolute;
	margin:-60px 0px 20px 68px;
}

#outer-switch:before{
	content: 'OFF';
	margin: -3px -54px;
	position: absolute;
}

#outer-switch:after{
	content: 'ON';
	margin: -12px 24px;
	position: absolute;
}

.inner-switch{
	height: 10px;
	width: 10px;
	border: 0px solid white;
	background: #FF0000;
	transition-duration: 0.2s;
}

/* WRAPPER - BOTTOM */

.wrapper-bottom{
	position: relative;
	background: white;
	text-align: center;
}


	/*-----------------------ACTIVE CLASSES-----------------------------*/

/* switch active */
.isSwitchActive{
	margin: 0px 30px;
	transition-duration: 0.2s;
	background: #57ED78;
}

/* block active */
.active-state-green{
	background: #00FF83;
	transition-duration: 0.3s;
}

.active-state-red{
	background: #F90000;
	transition-duration: 0.3s;
}

.active-state-blue{
	background: #4529E5;
	transition-duration: 0.3s;
}

.active-state-yellow{
	background: #F3FF1E;
	transition-duration: 0.3s;
}


/*--------------------------------MEDIA QUERIES--------------------------------*/

@media only screen and (max-width: 800px) and (min-width: 300px) {
	/* TOP-LEFT */
	.top-left{
		background: #00743C;
		height: 150px;
		width: 150px;
		border-top-left-radius: 100px;
		position: relative;
		display: inline-block;
		box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
		border: 10px solid black;
	}

	/*  TOP - RIGHT  */
	.top-right{
		background: #770000;
		height: 150px;
		width: 150px;
		position: relative;
		display: inline-block;
		box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
		border: 10px solid black;
	}

	/*  BOTTOM - LEFT  */
	.bottom-left{
		background: #120074;
		height: 150px;
		width: 150px;
		position: relative;
		display: inline-block;
		box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
		border: 10px solid black;
	}

	/*  BOTTOM - RIGHT  */
	.bottom-right{
		background: #B1BA00;
		height: 150px;
		width: 150px;
		border-bottom-right-radius: 100px;
		position: relative;
		display: inline-block;
		box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
		border: 10px solid black;
	}

	/* WRAPPER */
	.wrapper-top{
		position: relative;
		background: white;
		text-align: center;
		margin-top: 30%;
	}

	/* BUTTON */
	#inner-circle button:nth-child(2){
		height: 30px;
		background: #57ED78;
		box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
	}
	
	#inner-circle button:nth-child(3){
		height: 30px;
		box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
	}

	/* MODAL */
	.modal{
		margin: auto;
		position: absolute;
		display: none;
		z-index: 500;
		height: 350px;
		width: 373px;
	}

	.modal h2{
		padding: 10%;
		font-size: 30px;
		margin-top: 25%;
	}

	.modal h3{
		font-size: 30px;
	}

	/*-----------------------ACTIVE CLASSES-----------------------------*/

	/* switch active */
	.isSwitchActive{
		margin: 0px 30px;
		transition-duration: 0.2s;
		background: #57ED78;
	}

	/* block active */
	.active-state-green{
		background: #00FF83;
		transition-duration: 0.3s;
	}

	.active-state-red{
		background: #F90000;
		transition-duration: 0.3s;
	}

	.active-state-blue{
		background: #4529E5;
		transition-duration: 0.3s;
	}

	.active-state-yellow{
		background: #F3FF1E;
		transition-duration: 0.3s;
	}
	
}
            
          
!
            
              /* USING IIFE */
(function() {
  /* USER GLOBAL */
  var userSeq = [];
  var userTurn = 0;
  /* SIMON GLOBAL */
  var simonSeq = [];
  var simonTurn = 0;
  /* GLOBAL GLOBAL */
  var randomInterval; //for set interval
  var starter;
  var counter = 1;
  var stricto = false;
  var timerCount = [1000, 700, 500, 300];
  /*---------------------------------------DOM ELEMENTS FOR BUTTONS---------------------------------------- */
  var switcher = document.getElementsByClassName("inner-switch");
  var start = document.getElementById("start-btn");
  var strict = document.getElementById("strict-btn");
  var blocks = document.querySelectorAll("div .block");
  var level = document.getElementById("levelDisplay");

  /*---------------------------------------TOGGLE BUTTON---------------------------------------- */
  //BUTTON FOR SWITCHER ON AND OFF

  switcher[0].addEventListener("click", function() {
    switcher[0].classList.toggle("isSwitchActive"); //toggles from inner-switch to isSwitchActive

    //if switcher has isSwitchActive class return bool
    if (switcher[0].classList.contains("isSwitchActive")) {
      starter = true;
    } else {
      userSeq = [];
      userTurn = 0;

      simonSeq = [];
      simonTurn = 0;

      starter;
      counter = 1;

      stricto = false;
      timer = 1000;
      level.innerText = "00";
      starter = false;

      stricto = false;
      strict.style.background = "rgb(224, 26, 26)";
      start.addEventListener("click", startBtn);

      blocks.forEach(element => {
        element.removeEventListener("click", blockEvent);
      });

      clearInterval(randomInterval);
    }
  });

  /*--------------------------------------- START EVENT ----------------------------------------- */
  start.addEventListener("click", startBtn);
  function startBtn() {
    if (starter) {
      //    randomInterval = setInterval(simon, 1000);
      setTimeout(simon, 1000);
      level.innerText = counter;

      blocks.forEach(element => {
        element.addEventListener("click", blockEvent);
      });

      start.removeEventListener("click", startBtn);
    } else {
      alert("TURN SIMON ON!!!");
    }
  }

  /*--------------------------------------- STRICT BUTTON ----------------------------------------- */
  strict.style.background = "rgb(224, 26, 26)";

  strict.addEventListener("click", function() {
    if (starter) {
      if (strict.style.background === "rgb(224, 26, 26)") {
        stricto = true;
        strict.style.background = "#57ED78";
      } else {
        stricto = false;
        strict.style.background = "rgb(224, 26, 26)";
      }
    } else {
      alert("TURN SIMON ON!!!");
    }
  });

  /*------------------------------- SIMON WILL GENERATE RANDOM NUMBER ------------------------------- */
  //this will initate the game

  function simon() {
    if (counter === 21) {
      clearInterval(randomInterval);
      document.getElementsByClassName("modal")[0].style.display = "block";
      blocks.forEach(element => {
        element.removeEventListener("click", blockEvent);
      });
    } else {
      blocks.forEach(element => {
        element.removeEventListener("click", blockEvent);
      });

      var randNum = Math.floor(Math.random() * 4);
      console.log("simonRANDOM", randNum);
      simonSeq.push(randNum.toString());
      simonTurn++;
      level.innerText = counter;
      // console.log('c ' + counter , 's ' + simonTurn);
      userTurn = 0;
      playInput(randNum.toString());
    }
  }

  /*--------------------------------BLOCKS EVENTS && USER INTERACTION------------------------------------ */
  //EVENT FOR BLOCKS
  function blockEvent() {
    // console.log('user');
    userSeq.push(this.id);
    animateBlock(this.id);
    checkSequence(this.id);

    if (userTurn === simonTurn) {
      // if(simonSeq.length === userSeq.length){
      simonTurn = 0;

      blocks.forEach(element => {
        element.removeEventListener("click", blockEvent);
      });
      // }
    }
  }

  /*---------------------------------------PLAY INPUT----------------------------------------- */
  function playInput(numForBlock) {
    // console.log(typeof this.id); //check data type. should be STRING
    // console.log(this); //will target the whole <div class="top-left block" id="0"> ... </div>
    var miliSec;

    if (counter < 6) {
      console.log("damn");
      miliSec = timerCount[0];
    } else if (counter < 11) {
      console.log("uno");
      miliSec = timerCount[1];
    } else if (counter < 16) {
      console.log("dos");
      miliSec = timerCount[2];
    } else if (counter < 21) {
      console.log("tres");
      miliSec = timerCount[3];
    }

    animateBlock(numForBlock);
    if (counter !== simonTurn) {
      randomInterval = setTimeout(simon, miliSec);
    } else {
      blocks.forEach(element => {
        element.addEventListener("click", blockEvent);
      });
    }
  }

  /*---------------------------------------CLASS REMOVER----------------------------------------- */
  function removeClass(elementToRemove) {
    var htmlElement = elementToRemove; // HTML element
    var classToRemove = elementToRemove.classList[2]; //string class state

    var interval = setInterval(function() {
      htmlElement.classList.remove(classToRemove);
      clearInterval(interval);
    }, 1000);
  }

  /*---------------------------------------ANIMATE BLOCK----------------------------------------- */
  function animateBlock(blockNum) {
    switch (blockNum) {
      case "0":
        document
          .getElementsByClassName("top-left")[0]
          .classList.add("active-state-green");
        document.getElementsByClassName("top-left-audio")[0].play();
        removeClass(document.getElementsByClassName("top-left")[0]);
        break;

      case "1":
        document
          .getElementsByClassName("top-right")[0]
          .classList.add("active-state-red");
        document.getElementsByClassName("top-right-audio")[0].play();
        removeClass(document.getElementsByClassName("top-right")[0]);
        break;

      case "2":
        document
          .getElementsByClassName("bottom-left")[0]
          .classList.add("active-state-blue");
        document.getElementsByClassName("bottom-left-audio")[0].play();
        removeClass(document.getElementsByClassName("bottom-left")[0]);
        break;

      case "3":
        document
          .getElementsByClassName("bottom-right")[0]
          .classList.add("active-state-yellow");
        document.getElementsByClassName("bottom-right-audio")[0].play();
        removeClass(document.getElementsByClassName("bottom-right")[0]);
        break;
    }
  }

  /*---------------------------------------CHECK SEQUENCE----------------------------------------- */
  function checkSequence(theId) {
    var miliSec;

    if (counter < 6) {
      miliSec = timerCount[0];
    } else if (counter < 11) {
      miliSec = timerCount[1];
    } else if (counter < 16) {
      miliSec = timerCount[2];
    } else if (counter < 21) {
      miliSec = timerCount[3];
    }

    if (simonSeq[userTurn] === userSeq[userTurn]) {
      userTurn++;
      // console.log(userTurn , simonTurn);
      if (userTurn === simonTurn) {
        counter++;
        userSeq = [];
        simonSeq = [];
        playInput(theId);
      }
    } else {
      document.getElementsByClassName("error")[0].play();

      // console.log('stricto ', stricto )
      if (stricto) {
        counter = 1;
        simonTurn = 0;
        userTurn = 0;
        simonSeq = [];
        userSeq = [];
        level.innerText = "00";
        setTimeout(simon, 1000);
      } else {
        userSeq = [];
        userTurn = 0;
        blocks.forEach(element => {
          element.removeEventListener("click", blockEvent);
        });
        var i = 0;

        var interval = setInterval(function() {
          animateBlock(simonSeq[i.toString()]);
          console.log(simonSeq[i.toString()]);
          i++;

          // arr.length === i ? clearInterval(interval) :
          if (simonSeq.length === i) {
            clearInterval(interval);

            blocks.forEach(element => {
              element.addEventListener("click", blockEvent);
            });
          }
        }, miliSec);
      }
    }
  }

  function checkCounter(counterCount) {}
})();

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

Console