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.

            
              div.margin
  div.simon
    div.inside
      div.control
        div.onlight 
        h1.simontext.title Simon 
        text.r ®
        div.con
         div.countbox
           p.count --
         div.startbutton
           button.start
         div.strictbutton
           button.strict
           div.light
        div.textrow
          p.counttxt Count
          p.starttxt Start
          p.stricttxt Strict
          div.onoffswitch
            input(type="checkbox")(name="onoffswitch").onoffswitch-checkbox#myonoffswitch
            label.onoffswitch-label(for="myonoffswitch")
              span.onoffswitch-inner
              span.onoffswitch-switch  
      div.left.topleft.color#1
        audio#audio1(src="https://s3.amazonaws.com/freecodecamp/simonSound1.mp3")
      div.right.topright.color#2
        audio#audio2(src="https://s3.amazonaws.com/freecodecamp/simonSound2.mp3")
      div.left.bottomleft.color#3
        audio#audio3(src="https://s3.amazonaws.com/freecodecamp/simonSound3.mp3")
      div.right.bottomright.color#4
        audio#audio4(src="https://s3.amazonaws.com/freecodecamp/simonSound4.mp3")
      audio#audio5(src="https://www.freesound.org/people/Autistic%20Lucario/sounds/142608/download/142608__autistic-lucario__error.wav")
            
          
!
            
              body {
  background-image: url('https://unsplash.com/photos/h0Vxgz5tyXA/download');
 background-size: cover;
 -webkit-background-size: cover;
 -moz-background-size: cover;     -o-background-size: cover;
  background-repeat: no-repeat;
}
.margin{
  margin-top:100px;
}
.simontext {
  text-align:center;
}
.onlight {
  height:12px;
  width:12px;
  background-color: #014d00;
  border:solid 1px #013300;
  border-radius:50%;
  position:relative;
  z-index:-1;
  margin-left:auto;
  margin-right:auto;
  margin-top:14px;
}
.r{
  font-size:15px;
  float:right;
  margin-right:20px;
  margin-top:-63px;
  color:black;
}
.title {
  color:black;
  font-weight:900;
  margin-top:3px;
  font-family: 'Titillium Web', sans-serif;
  font-size:58px;
  margin-right:10px;
}
.simon {
  border-radius:50%;
  height:450px;
  width:450px;
  margin-left: auto;
  margin-right:auto;
  background-color:#262626;
  -webkit-box-shadow: 0px 0px 3px 3px rgba(0,0,0,0.5);
-moz-box-shadow: 0px 0px 3px 3px rgba(0,0,0,0.5);
  box-shadow: 0px 0px 3px 3px rgba(0,0,0,0.5);
}
.inside {
  border-radius:50%;
  height:400px;
  width:400px;
  margin: 0 auto;
}
.control {
  border:solid 8px #262626;
  height:230px;
  width:230px;
  margin-left:85px;
  margin-top:110px;
  border-radius:50%;
  background-color:#C0C0C0;
  position:absolute;
  z-index:10;
}
.left,
.right {
  background-color:green;
  width:50%;
  height:50%;
  margin:0px;
}
.left {
  float:left;
}
.right {
  float:right;
}
.topleft {
  border-right:solid 10px #262626;
  margin-top:25px;
  border-top-left-radius:100%;
  background-color: #00A74A;
  border-bottom:solid 10px #262626;
}
.topright {
  border-left:solid 10px #262626;
  border-top-right-radius:100%;
  margin-top:25px;
  background-color:#9F0F17;
  border-bottom:solid 10px #262626;
}
.bottomleft {
  border-right:solid 10px #262626;
  border-top:solid 10px #262626;
  border-bottom-left-radius:100%;
  background-color: #CCA707
}
.bottomright {
  border-left:solid 10px #262626;
  border-top:solid 10px #262626;
  border-bottom-right-radius:100%;
  background-color: #094A8F
}
h1 {
   -moz-user-select: none;
   -khtml-user-select: none;
   -webkit-user-select: none;
   -ms-user-select: none;
   user-select: none;
}
.countbox {
  width:60px;
  height:40px;
  border-radius:20%;
  border:solid 1px black;
  margin-left:20px;
  background-color:#494F35;
  -webkit-box-shadow: inset 0px 0px  3px 5px rgba(0,0,0,0.75);
  -moz-box-shadow: inset 0px 0px 3px 5px rgba(0,0,0,0.75);
  box-shadow: inset 0px 0px 3px 3px rgba(0,0,0,0.75);
  float:left;
}
button:active {
  background-color: #3e8e41;
  box-shadow: 0 1px #666;
  transform: translateY(2px);
}
.count {
  user-select:none;
  -webkit-user-select:none; 
  -moz-user-select:none;
  -ms-user-select: none;
  color:#323725;
  text-align:center;
  font-family:Orbitron;
  font-size:25px;
}
.con {
  margin-top:10px;
}
button.start {
  margin-left: 20px;
  margin-top:7px;
  height:25px;
  width:25px;
  background-color: #FE0002;
  border-radius:50%;
  border:solid 1px black;
}
button.strict{  
  height:25px;
  width:25px;
  background-color: #F2F021;
  border-radius:50%;
  margin-top:-25px;
  margin-right:38px;
  border:solid 1px black;
  float:right;
}
.light{
  height:8px;
  width:8px;
  border:solid 1px #31080F;
  background-color: #31080F;
  border-radius:50%;
  float:right;
  margin-right:46px;
  margin-top:-38px;
}
button {
    -webkit-box-shadow: 0px 2px 0px 1px rgba(0,0,0,0.75);
  -moz-box-shadow: 0px 2px 0px 1px rgba(0,0,0,0.75);
  box-shadow: 0px 2px 0px 1px rgba(0,0,0,0.75);
}
.counttxt {
  float:left;
  position:absolute;
  margin-left:34px;
}
.starttxt {
  margin-left:98px;
}
.stricttxt {
  float:right;
  position:relative;
  margin-top:-35px;
  margin-right:36px;
}
.textrow {
  user-select:none;
  -webkit-user-select:none; 
  -moz-user-select:none;
  -ms-user-select: none;
  font-family: 'Yanone Kaffeesatz', sans-serif;
  margin-top:5px;
  font-size:18px;
  color:black;
}
// On Off 
.onoffswitch {
      margin-left:auto;
      margin-right:auto;
      position: relative; 
      width: 60px;
      -webkit-user-select:none; 
      -moz-user-select:none;
      -ms-user-select: none;
}
.onoffswitch-checkbox {
        display: none;
}
.onoffswitch-label {
        display: block; 
        overflow: hidden; 
        cursor: pointer;
        border: 2px solid #262626;
        border-radius: 5px;
    }
.onoffswitch-inner {
        display: block; 
        width: 200%;
        margin-left: -100%;
        transition: margin 0.3s ease-in 0s;
    }
.onoffswitch-inner:before, .onoffswitch-inner:after {
        display: block;
        float: left; 
        width: 50%; 
        height: 20px; 
        padding: 0; 
        line-height: 20px;
        font-size: 10px; 
        color: white; 
        font-family: Trebuchet, Arial, sans-serif; 
        font-weight: bold;
        box-sizing: border-box;
    }
.onoffswitch-inner:before {
        content: "On";
        padding-left: 5px;
        background-color: #00709D;  
        color: #FFFFFF;
    }
.onoffswitch-inner:after {
        content: "Off";
        padding-right: 5px;
        background-color:#595959;
        color: white;
        text-align: right;
    }
.onoffswitch-switch {
        display: block; 
        width: 24px;
        margin: 0px;
        background: #999999;
        position: absolute; top: 0; bottom: 0;
        right: 36px;
        border: 2px solid #262626; border-radius: 5px;
        transition: all 0.3s ease-in 0s; 
    }
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
        margin-left: 0;
    }
    .onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
        right: 0px; 
    }
@keyframes animTopLeft {
  0% {background-color: #00A74A}
  50% {background-color: #00ff71}
  100% {background-color: #00A74A}
}
@keyframes animTopRight {
  0% {background-color: #9F0F17}
  50% {background-color: #eb2e38}
  100% {background-color: #9F0F17}
}
@keyframes animBottomLeft {
   0% {background-color: #CCA707}
  50% {background-color: #F3F34E}
  100% {background-color: #CCA707}
}
@keyframes animBottomRight {
  0% {background-color: #094A8F}
  50% {background-color: #0f7cf0}
  100% {background-color: #094A8F}
}
.topleftanim {
    animation-name: animTopLeft;
    animation-duration: 1000ms;
  
}
.toprightanim{
    animation-name: animTopRight;
    animation-duration: 1000ms;
}
.bottomleftanim{
  animation-name: animBottomLeft;
  animation-duration: 1000ms;   
}
.bottomrightanim {
      animation-name: animBottomRight;
    animation-duration: 1000ms;
}
            
          
!
            
              var switchstate = 0;
var strictstate = 0;
var commandarr = [];
var restart = 0;
var userArr = [];
var num = 0;
var command;
var val;
disabled();
function disabled() {
  $(".topleft").css("pointer-events","none");
  $(".topright").css("pointer-events","none");
$(".bottomright").css("pointer-events","none");
$(".bottomleft").css("pointer-events","none");
}
function enabled() {
   $(".topleft").css("pointer-events","auto");
  $(".topright").css("pointer-events","auto");
$(".bottomright").css("pointer-events","auto");
$(".bottomleft").css("pointer-events","auto");
}
$("#myonoffswitch").click(function() {
  countChange();
});

function countChange() {
  if (switchstate === 0) {
    $(".count").css("color", "black");
    $(".onlight").css("background-color", "#01DF00");
    switchstate = 1;
    restart = 0;
  } else if (switchstate == 1) {
    $(".count").css("color", "#323725");
    $(".onlight").css("background-color", "#014d00");
    $(".light").css("background-color", "#31080F");
    strictstate = 0;
    restartSimon();
    commandarr = [];
    switchstate = 0;
  }
}

function restartSimon() {
  disabled();
  $(".count").text("--");
  commandarr = [];
  userArr = [];
  command = 0;
  restart = 0;
  $(".topleft").removeClass(".toprightanim");
  $(".bottomleft").removeClass(".bottomleftanim");
  $(".topright").removeClass(".toprightanim");
  $(".bottomright").removeClass(".bottomrightanim");
}

function random(min, max) {
  return Math.floor(Math.random() * (max - min)) + min;
}
$(".strict").click(function() {
  if (strictstate === 0 && switchstate == 1) {
    $(".light").css("background-color", "#c4223e");
    strictstate = 1;
  } else if (strictstate == 1 && switchstate == 1) {
    $(".light").css("background-color", "#31080F");
    strictstate = 0;
  }
});
$(".start").click(function() {
  if (restart == 1 && switchstate == 1) {
    restartSimon();
    
  } else if (switchstate == 1 && restart === 0) {
    restart = 1;
    simon();
  }
});

function simon() {
  disabled();
  var rand = random(1, 5);
  if(rand!==commandarr[commandarr.length-1]) {
  commandarr.push(rand);
  }
else if(rand==commandarr[commandarr.length-1]) {
  if(rand<3) {
    commandarr.push(rand+1);
  }
 else if(rand>=3){
   commandarr.push(rand-1);
 } 
} 
 if ($(".count").text() == "20") {
    alert("You win!");
    restartSimon();
    return;
  }
  userArr=[];
  if (commandarr.length <= 20) {
    $(".count").text(commandarr.length.toString());
    animArr();
    num = 0;
    userInput(num);
  }
}

function exclam() {
  disabled();
  audio5.play();
  if(strictstate==0) {
  $("button").prop('disabled', true);
  
  animTopLeft();
  animTopRight();
  animBottomLeft();
  animBottomRight();
  $(".count").fadeOut("150");
  $(".count").fadeIn("150");
  $("button").prop('disabled', false);
} else if (strictstate==1) {
    $("button").prop('disabled', true);
  
  animTopLeft();
  animTopRight();
  animBottomLeft();
  animBottomRight();
  $(".count").fadeOut("150");
  $(".count").fadeIn("150");
  $("button").prop('disabled', false);
  setTimeout(function() {
     restartSimon();
  },800)
  repeat();
}
}
function repeat() {
     setTimeout(function() {
      simon();
    }, 800);
}

$(".topleft").click(function() {
  animTopLeft();
  if(Number($('#1').attr('id')) ==commandarr[val]) {
    if (val == commandarr.length-1) {
      repeat();
    } else {
   val++ ;
    }
  } else if (Number($('#1').attr('id')) !==commandarr[val]) {
    exclam();
    disabled();
    setTimeout(function() {
          animArr();
    },1000);
  }
});

$(".topright").click(function() {
  animTopRight();
    if(Number($('#2').attr('id')) ==commandarr[val]) {
    if(val == commandarr.length-1) {
      repeat();
    } else {
   val++ ;
    }
  } else if (Number($('#2').attr('id')) !==commandarr[val]){
    exclam();
    disabled();
    setTimeout(function() {
          animArr();
    },1000);
  }
});

$(".bottomleft").click(function() {
  animBottomLeft();
  if(Number($('#4').attr('id')) ==commandarr[val]) {
   if (val == commandarr.length-1) {
      repeat();
    } else {
   val++ ;
    }
  } else if (Number($('#4').attr('id')) !==commandarr[val]) {
    exclam();
    setTimeout(function() {
          animArr();
    },1000);
  }
});

$(".bottomright").click(function() {
  animBottomRight();
    if(Number($('#3').attr('id')) ==commandarr[val]) {
    if(val == commandarr.length-1) {
      repeat();
    } else {
   val++ ;
    }
  } else if (Number($('#3').attr('id')) !==commandarr[val]){
    exclam();
    disabled();
    setTimeout(function() {
          animArr();
    },1000);
  }
});

function animTopLeft() { $(".topleft").addClass("topleftanim"); 
  audio1.play();
  setTimeout(function() {
    $(".topleft").removeClass("topleftanim");
  },1000);
}

function animTopRight() {
 
$(".topright").addClass("toprightanim");
  audio2.play();
  setTimeout(function() {
    $(".topright").removeClass("toprightanim");
    
  },1000);
}

function animBottomLeft() {
  
 audio4.play(); $(".bottomleft").addClass("bottomleftanim");
                          
  setTimeout(function() {
   $(".bottomleft").removeClass("bottomleftanim");
  }, 1000);
}

function animBottomRight() {
audio3.play();
  $(".bottomright").addClass("bottomrightanim");            
  setTimeout(function() {
   $(".bottomright").removeClass("bottomrightanim");
  }, 1000);
}

function animArr2(val) {
  command = commandarr[val];
  if (command == 1) {
    animTopLeft();
  }
  if (command == 2) {
    animTopRight();
  }
  if (command == 3) {
    animBottomRight();
  }
  if (command == 4) {
    animBottomLeft();
  }
}

function animArr() {
  var int2 = setInterval(function() {
    enabled();
  }, (commandarr.length*1000));
  val =0;
  disabled();
  var i = 0;
	var int = setInterval(function() {
		animArr2(i);
        i++;
        if (i >= commandarr.length) {
         
			clearInterval(int);
        
        }
   }, 900);
}
var audio1 = document.getElementById("audio1");
var audio2 = document.getElementById("audio2");
var audio3 = document.getElementById("audio3");
var audio4 = document.getElementById("audio4")
var audio5 = document.getElementById("audio5")
            
          
!
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