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.

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

              
                <link href='https://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'>

<body>

  <div class="container text-center" align="center">
    <div class="behindcont">
      
        <div class="top-left sidebutton click">
      </div>
        <div class="top-right sidebutton click rightside">
      </div>
      
      
        <div class="bottom-left sidebutton bottomadjust click">
      </div>
        <div class="bottom-right sidebutton bottomadjust click rightside">
      </div>
      
    </div>
    <div class="centercont">
      <div class="row">
        <h1>Simon</h1>
      </div>
      <div class="row">
        <h4>Count</h4>
        <div class="countdis text-center">
          <h1 id="counter">1</h1>
        </div>
      </div>
      <div class="row">
        <p style="margin-bottom: 8px; font-size: 14px; word-spacing: 8px;">Start Strict</p>

      </div>
      <div class="row">

        <div class="stbtn redbtn click">

        </div>
        <div class="stbtn yellowbtn click">

        </div>
        <div class="stbtn dullbtn">
        </div>
      </div>
    </div>
  </div>
</body>
              
            
!

CSS

              
                

body{
  background-color: grey;
}
container{
  width: 500px;
  height: 500px;
}

.rightside{
  margin-left: 0px;
}

#counter{
  margin: 2px 0 0px 0;
}
.bottomadjust 
{
  margin-top: -16px;
}
.centercont{
  width: 250px;
  height: 250px;
  position: absolute;
  z-index: 2;
  background-color: white;
  display: inline-block;
  top: 125px ;
  right: 320px;
  border-radius: 100%;
  border-width: 20px;
  border-color: black;
  border-style: solid;  
  font-family: Oswald;
  color: black;
  -webkit-filter: brightness(75%)
  
}

.countdis{
  color: red;
  margin-top: -20px;
  border-radius: 10%;
  background-color: #330000;
  border-color: #333333;
  border-width: 2px;
  border-style: solid;
  height: 40px;
  width: 80px;
  z-index: 1;
}

.stbtn{
   border-radius: 100%;
   border-width: 2px;
   border-style: solid;
   border-color: #333333; 
   width: 20px;
   height: 20px;
   margin-top: -20px;
   display: inline-block;
   
}

.redbtn{
  background-color: red;
  color: red;
  margin-right: 10px;
  margin-left: 10px;
  -webkit-filter: brightness(100%);
}

.yellowbtn{
  background-color: yellow;
  color: yellow;
  -webkit-filter: brightness(100%);
}
.dullbtn{
  background-color: grey;
  height: 4px;
  width: 4px;
  border-width: 1px;
  margin-bottom: 7px;
  }
.sidebutton{
  height:250px;
  width: 250px;
  
  border-width: 15px;
  border-color: #333333;
  border-style: solid;  
 
}
.top-left {
    background-color: #33FF33;
    -moz-border-radius: 250px 0 0 0;
    border-radius: 250px 0 0 0;
    position: absolute;
    display: inline-block;
    right: 455px;
    -webkit-filter: brightness(70%);
    
    
}

.top-right {
    background-color: red	;
    -moz-border-radius: 0 250px 0 0;
    border-radius: 0 250px 0 0;  
    -webkit-filter: brightness(70%);
    right: 205px;
    position: absolute;
}

.bottom-right {
    background-color: blue;
    -moz-border-radius: 0  0 250px 0;
    border-radius: 0 0 250px 0;
    -webkit-filter: brightness(70%);
    top: 265px;
    right: 205px;
    position: absolute;
}


.bottom-left {
    background-color:yellow;
    -moz-border-radius: 0  0 0 250px;
    border-radius: 0 0 0 250px;
    top: 265px;
    right: 455px;
    -webkit-filter: brightness(70%);
    position: absolute;
    
}
.active{
  -webkit-filter: brightness(100%)
}
.noclick {
  pointer-events: none !important;
}
.dullred{
  background-color: red;
}
.behindcont{
  width: 100%;
  height: 100%;
  position: absolute;
  overflow: hidden;
}
              
            
!

JS

              
                var strict = false;
var start = false;
var count = 0;
var playerarray = [];
var playercount = 0;
var sound1;
var sound2;
var sound3; 
var sound4;
//sound
function sound(src) {
    this.sound = document.createElement("audio");
    this.sound.src = src;
    this.sound.setAttribute("preload", "auto");
    this.sound.setAttribute("controls", "none");
    this.sound.style.display = "none";
    document.body.appendChild(this.sound);
    this.play = function(){
        this.sound.play();
    }
    this.stop = function(){
        this.sound.pause();
    }
}

function loadsound(){
  sound1 = new sound("https://s3.amazonaws.com/freecodecamp/simonSound1.mp3")
  sound2 = new sound("https://s3.amazonaws.com/freecodecamp/simonSound2.mp3")
  sound3 = new sound("https://s3.amazonaws.com/freecodecamp/simonSound3.mp3")
  sound4 = new sound("https://s3.amazonaws.com/freecodecamp/simonSound4.mp3")
}




function randomset() {
  var options = ["top-left", "top-right", "bottom-left", "bottom-right"];
  return options[Math.floor(Math.random() * 3) + 1];
}

function evaluate(playercount, array, playerarray) {
  if (playerarray[playercount] != array[playercount]) {
    refresh();

    if (strict == false) {
      $(".click").addClass("noclick");
      flash(0, "X X");
      setTimeout(function() {
        sequence(0, window.array);
      }, 1500)

    } else {
      count = 0;
      window.array = [randomset()];
      $(".click").addClass("noclick");
      flash(0, "X X");
      setTimeout(function() {
        sequence(0, window.array);
      }, 1500)
    }
  } else if (count < 19 && playercount == count) {
    $(".click").addClass("noclick");
    flash(0, "YAY");
    setTimeout(function() {
    refresh();
    window.array.push(randomset());
    count++;
    sequence(0, window.array);},1500);
  } else if(playercount<count){
    window.playercount++;
  }
  else{
    $(".click").addClass("noclick");
    flash(0, "WIN");
    sequence(0,["top-left"]);
    sequence(0,["top-right"]);
    sequence(0,["bottom-left"]);
    sequence(0,["bottom-right"]);
    setTimeout(function() {
        refresh();
        window.count=0;
        window.array=[randomset()];
        flash(0,"NEW");
        setTimeout(function(){
          sequence(0, window.array);
        },1000)
      }, 3000)
  }
};

function brighten(classe) {
  $("." + classe).addClass("active");
};

function unbrighten(classe) {
  $("." + classe).removeClass("active");
};

function callback(i, classe) {
  return function() {
    $("." + classe).removeClass("active");
    console.log(classe, i);
  };
};

function sequence(x, array) {
  if (x >= array.length) {
    return
  };
  setTimeout(function() {
    $("." + array[x]).addClass("active");
    if(array[x]=="top-left")
      {
        sound1.play();
      }
    else if(array[x]=="top-right")
      {
        sound2.play();
      }
    else if(array[x]=="bottom-left")
      {
        sound3.play();
      }
    else{
      sound4.play();
    }
    //console.log(x, array[x])
    setTimeout(function() {
      callback(x, array[x])();
      sequence(++x, array);
      $(".click").removeClass("noclick");
    }, 400);
  }, 400);
}

function flash(i, message) {
  if (i == 2) {
    return
  }
  setTimeout(function() {
    $("#counter").html(message);
    setTimeout(function() {
      $("#counter").html(count + 1);
      flash(++i, message);
    }, 400);
  }, 400);

}

function refresh() {
  playerarray = [];
  playercount = 0;
}

$(document).ready(function() {
  $(".top-left").mouseup(function() {
    if (playercount <= count) {
      unbrighten("top-left");
      
      playerarray.push("top-left");
      console.log("Playerarray:" + playerarray);

      evaluate(playercount, array, playerarray);
    }
  });
  $("body").mouseup(function(){
    unbrighten("top-left");
    unbrighten("top-right");
    unbrighten("bottom-left");
    unbrighten("bottom-right");
  })
  $(".top-left").mousedown(function() {
    brighten("top-left");
    sound1.play();
  });
  $(".bottom-left").mouseup(function() {
    if (playercount <= count) {
      unbrighten("bottom-left");
      
      playerarray.push("bottom-left");
      console.log("Playerarray:" + playerarray);

      evaluate(playercount, array, playerarray);
    }
  });
  $(".bottom-left").mousedown(function() {
    brighten("bottom-left")
    sound3.play();
  });
  $(".top-right").mouseup(function() {
    if (playercount <= count) {
      unbrighten("top-right");
      playerarray.push("top-right");
      console.log("Playerarray:" + playerarray);

      evaluate(playercount, array, playerarray);
    }
  });
  $(".top-right").mousedown(function() {
    brighten("top-right");
    sound2.play();
  });
  $(".bottom-right").mouseup(function() {
    if (playercount <= count) {
      unbrighten("bottom-right")
      playerarray.push("bottom-right");
      console.log("Playerarray:" + playerarray);

      evaluate(playercount, array, playerarray);
    }
  });
  $(".bottom-right").mousedown(function() {
    brighten("bottom-right")
    sound4.play();
  });

  $(".redbtn").on("click", function() {
    start = true;
    loadsound();
    array = [randomset()];
    count = 0;
    $("#counter").html("1");
    playerarray = [];
    playercount = 0;
    $(".click").addClass("noclick");
    sequence(0, array);
  });

  $(".yellowbtn").on("click", function() {
    if (strict == false) {
      strict = true;
      $(".dullbtn").addClass("dullred");
    } else {
      strict = false;
      $(".dullbtn").removeClass("dullred");
    }
  });

});
              
            
!
999px

Console