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.

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

<div class='container'>
<div class='navbar-inverse navbar' id='head'>
  <table>
    <tr id="celColorChange">
        <td>S</td>
        <td>I</td>
        <td>M</td>
        <td>O</td>
        <td>N</td>
    </tr>
</table>
</div>
  <div class='container'>
<div class='simon'>
  <div class='red player' id='red' src='https://s3.amazonaws.com/freecodecamp/simonSound2.mp3'></div>
  <div class='yellow player' id='yellow'></div>
  <div class='center'><div class='name'>Simon</div>
    <input class='moves' type='text' disabled value=""/>
  <div class='btn start' id='start'>Start</div>
  <div class='btn strict' id='strict'>Strict</div>
    <div class='slider-scale'>
      <div class=''><div class='gameon switch'></div><div class='gameoff'></div></div>
      <div class='slider'></div>
    </div>
  </div>
  <audio id='greenNote' src='https://s3.amazonaws.com/freecodecamp/simonSound1.mp3' autostart='false'></audio>
  <audio id='redNote' src='https://s3.amazonaws.com/freecodecamp/simonSound2.mp3' autostart='false'></audio>
  <audio id='blueNote' src='https://s3.amazonaws.com/freecodecamp/simonSound3.mp3' autostart='false'></audio>
  <audio id='audio' src='http://www.soundjay.com/button/sounds/button-17.mp3' autostart='false'></audio>
  <audio id='yellowNote' src='https://s3.amazonaws.com/freecodecamp/simonSound4.mp3' autostart='false'></audio>
  <audio id='failNote' src='http://k003.kiwi6.com/hotlink/clrtgq79wz/simonSound4.mp3'  autostart='false'></audio>
  <div class='blue player' id='blue'></div>
  <div class='green player' id='green'></div>
  
</div></div>
</div>
            
          
!
            
              .btn {
  border: 1px solid black;
  font-size: 13px;
  padding: 15px;
  margin-top: -15px;
  border-radius: 50%;
  box-shadow: 0 1px 1px darkgrey, 0 2px 2px darkgrey, 0 3px 3px black, 0 4px 0 black, 0 5px 0 black;
  opacity: .5;
  width: 60px;
  cursor: grab;
}
table{
  margin-left: auto;
  margin-right: auto;
}
#celColorChange{
  font-size: 36px;
/*   color: white; */
  font-weight: strong;
  text-align: center;
/*   margin-left: 50px; */
/*   transform: rotateX(15deg); */
}

.gameoff{
  margin-left: 39px;
  position: absolute;
  margin-top: 4px;
  opacity: 1;
  background-color: red;
  width: 53px;
  height: 20px;
  color:grey;
  border-radius: 7px;
  text-align: right;
  transition: all 1.1s ease;
/*   overflow: hidden; */
}
.gameon{
/*   font-size: 16px; */
  margin-top: 4px;
  margin-left: 1px;
  opacity: 1;
  width: 55px;
  height: 20px;
  background-color: green;
  border-radius: 7px;
  position: absolute;  
  transition: all 1s ease;
}
.gameon.switch{
/*   opacity: 0; */
  overflow: hidden;
/*   margin-left: -5px; */
  width: 0;
  transition: all 1s ease;
}
.gameoff.switch{
/*   opacity: 0; */
  overflow: hidden;
/*   z-index: -1; */
  margin-left: 90px;
  width: 0;
  transition: all .8s ease;
}

.simonMove{
/*   z-index: -1; */
/*   opacity: 0; */
  pointer-events: none;
}

.btn:active {
  margin-bottom: -10px;
  box-shadow: none;
  transition: all .1s ease;
}

.slider-scale {
  background-color: darkgrey;
  width: 95px;
  height: 25px;
  margin-top: 35px;
  margin-left: 65px;
  border-radius: 8px;
  color:black;
/*   overflow: hidden; */
  -webkit-box-shadow: inset -4px 4px 1px -1px black, inset -6px 6px 1px 1px grey;
  box-shadow: inset -4px 4px 1px -1px black, inset -6px 6px 1px 1px grey;
  /*   box-shadow:inset -5px -5px 10px -1px rgba(0,0,0,0.75); */
}

.slider-scale.on{
  color: black;
/*   margin-left: 150px; */
}

.slider {
  width: 35px;
  height: 25px;
  background-color: #2989d8;
/*   background-color:black; */
  cursor: grab;
  border-radius: 7px;
  box-shadow: 3px 1px 0 0 white, 3px 2px 0 0 black;
  transition: all 1s ease;
  /*   margin-top: 3px; */
}

.slider.off {}

.slider.on {
  box-shadow: -3px 1px 0 0 white, -3px 2px 0 0 black;
  margin-left: 60px;
/*   background: #2989d8; */
}


#strict.clicked:active {
  margin-bottom: -10px;
  box-shadow: none;
  transition: all .1s ease;
}

#strict.clicked {
  box-shadow: 0 1px 1px orange, 0 2px 2px black, 0 3px 3px orange, 0 4px 0 black, 0 5px 0 black, 4px 4px 40px 15px orange, 0 5px 9px 5px black;
  opacity: .8;
}

#start.clicked:active {
  margin-bottom: -10px;
  box-shadow: none;
  transition: all .1s ease;
}

#start.clicked {
  box-shadow: 0 1px 1px red, 0 2px 2px black, 0 3px 3px red, 0 4px 0 black, 0 5px 0 black, 4px 4px 40px 15px red, 0 5px 9px 5px black;
  opacity: .8;
}

.start {
  background-color: red;
}

.strict {
  background-color: orange;
  /*   opacity: .3; */
}

.moves {
  font-family: 'Geostar Fill', cursive;
  width: 50px;
  height: 50px;
  margin-left: 25px;
  margin-top: 35px;
  background-color: #5C1515;
  border: 2px solid black;
  font-size: 22px;
  text-align: center;
  color: #792E2E;
}

.center {
  background-color: grey;
  height: 250px;
  width: 250px;
  border: 15px solid black;
  z-index: 10;
  margin: 0 auto;
  margin-left: 125px;
  top: 192px;
  border-radius: 50%;
  overflow: hidden;
  position: absolute;
  color: black;
}

.name {
  margin-top: 10px;
  text-align: center;
  color: black;
  font-size: 26px;
/*   opacity: 0; */
}
.name:hover{
  -webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
  cursor: default;
}

.simon {
  width: 500px;
  height: 500px;
  background-color: black;
  margin-left: auto;
  margin-right: auto;
  box-shadow: 8px 8px 8px 8px grey, 17px 17px 17px 17px black, 18px 18px 18px 5px grey, 100px 100px 100px 1px grey, 200px 200px 200px 1px pink, 50px 50px 50px 1px red, 60px 60px 60px 1px yellow, 70px 70px 70px 1px yellow, 110px 110px 110px 1px blue;
    z-index: 2;
  border-radius: 250px;
}


/* .simon{
  z-index:900;
} */

.red,
.yellow,
.blue,
.green {
  cursor: grab;
  z-index: 1;
  position: relative;
  margin-top: 12px;
  margin-right: 5px;
  width: 230px;
  height: 230px;
  margin-bottom: 5px;
  opacity: .5;
}
.window{
  background-color: blue;
  width: 95px;
  height: 23px;
  overflow: hidden;
}

.red:hover,
.yellow:hover,
.blue:hover,
.green:hover {
/*   cursor: pointer; */
}

.red:active {
  opacity: 1;
  transition: all 5 ease;
  box-shadow: none;
  box-shadow: 4px 4px 40px 1px red;
}

.yellow:active {
  opacity: 1;
  transition: all 5 ease;
  box-shadow: none;
  box-shadow: 4px 4px 40px 1px yellow, 0 5px 5px 5px black;
}

.green:active {
  opacity: 1;
  transition: all 5 ease;
  box-shadow: none;
  box-shadow: 4px 4px 40px 1px green, 0 5px 5px 5px black;
}

.blue:active {
  opacity: 1;
  transition: all 5 ease;
  box-shadow: none;
  box-shadow: 4px 4px 40px 1px blue, 0 5px 5px 5px black;
}

.red {
  background-color: red;
  border-top-left-radius: 225px;
  margin-left: 15px;
  float: left;
  /*   box-shadow: 1px 1px 0 pink, 2px 2px 0 pink, 3px 3px 0 pink, 4px 4px 0 pink; */
}

.yellow {
  background-color: yellow;
  border-top-right-radius: 225px;
  float: right;
  margin-right: 15px;
}

.green {
  background-color: green;
  border-bottom-left-radius: 225px;
  float: left;
  margin-left: 15px;
}

.blue {
  background-color: blue;
  border-bottom-right-radius: 225px;
  float: right;
  margin-right: 15px;
}

.lit {
  opacity: 1;
}


            
          
!
            
              var moveCount = 1;
var moves = [];
var colors = ['red', 'yellow', 'blue', 'green'];
var moved = 0;
var playerMoveCount = 0;
var lit = 400;
var rate = 1;
var timer = 400;
var play = false;
var strict = false;
var playerMove = false;
var newGame = true;
var rateVal = true;
var speedReset = true;
var slow = 3;
var counting;
var audioColors = {
  green: 'https://s3.amazonaws.com/freecodecamp/simonSound1.mp3',
  red: 'https://s3.amazonaws.com/freecodecamp/simonSound2.mp3',
  blue: 'https://s3.amazonaws.com/freecodecamp/simonSound3.mp3',
  yellow: 'https: //s3.amazonaws.com/freecodecamp/simonSound4.mp3',
  fail: 'http://k003.kiwi6.com/hotlink/clrtgq79wz/failsimon.mp3'
};
var celColorChange = document.getElementById('celColorChange').cells; 
var g = 0;
$(document).ready(function() {
  $('.red, .yellow, .blue, .green, .start, .strict').addClass('simonMove');
  // setInterval(cycle, 3000);
  setTimeout(function(){
    cycle(g);
  }, 2000);
  // cycle(g);
});
function cycle(id) {
  // for(var i = 0; i < celColorChange.length; i++){    
  // var g = 0;
  if(id < 5){
    simonColor = Math.round(Math.random() * 3);
    col = colors[g];    
    celColorChange[id].style.textShadow = '1px 1px 1px white, 2px 2px 2px '+col+', 3px 3px 3px '+col+', 4px 4px 4px black, 7px 7px 7px '+col+'';
    id++;
    // g++;
    setTimeout(function(){
      cycle(id);
    }, 1000);
  }else{
    id = 0;
    setTimeout(function(){
      cycle(id);
    })
    g++;
  }
  if(g == 4){
    g = 0;
  }
  // for(var i = 0; i < celColorChange.length; i++){    
  //   simonColor = Math.round(Math.random() * 3);
  //   col = colors[simonColor];    
  //   celColorChange[i].style.textShadow = '1px 1px 1px white, 2px 2px 2px '+col+', 3px 3px 3px '+col+', 4px 4px 4px black, 7px 7px 7px '+col+'';
  
  
}

function slowMove(id, from) {
  if (id === 0) {
    lose();
  }
}

$('.red, .yellow, .blue, .green').click(function() {
  $.each(colors, function() {
    $('.' + this + '').addClass('simonMove');
  });

  playNote(this.id + 'Note');
  if (playerMove) {
    playerMoved(this.id);
  }
});

function playerMoved(id) {
  slow = 3;
  clearInterval(counting);

  counting = setInterval(function() {
    slowMove(slow, "playerMoved");
    slow -= 1;
  }, 1000);
  if (id == moves[moved]) {
    moved++;
    playerMoveCount++;
    if (playerMoveCount === moveCount) {
      // cycle();
      $('.red, .green, .blue, .yellow').addClass('simonMove');
      speedReset = true;
      clearInterval(counting);
      rateVal = true;
      setTimeout(setMoves, 650);
      moveCount++;
      playerMove = false;
      playerMoveCount = 0;
      moved = 0;
    } else {
      setTimeout(function() {
        $.each(colors, function() {
          $('.' + this + '').removeClass('simonMove');
        });
      }, 150);
    }
  } else {
    lose();
  }

  if (playerMoveCount < moveCount) {
    playerMove = true;
  } else {
    playerMove = false;
    moved = 0;
  }
}

function lose() {
  clearInterval(counting);
  var loseNote = document.getElementById('failNote');
  loseNote.play();
  playerMoveCount = 0;
  moved = 0;
  $.each(colors, function() {
    $('.' + this + '').addClass('lit');
  });

  $('.red, .yellow, .green, .blue').addClass('simonMove');
  setTimeout(function() {
    $.each(colors, function() {
      $('.' + this + '').removeClass('lit');
    });
  }, 1500);

  if (strict) {
    moves = [];
    setTimeout(setMoves, 2490);
    moveCount = 1;
    timer = 1100;
    rate = 1;
    lit = 400;
    setTimeout(simonMove, 2500);
    playerMove = false;
  } else {
    playerMove = false;
    setTimeout(simonMove, 2500);
  }
}

$('.slider').click(function() {

  $(this).toggleClass('on');

  if ($(this).hasClass('on')) {
    setTimeout(function() {
      $('.start, .strict').removeClass('simonMove');
    }, 2000);
  } else {
    $('.start, .strict, .red, .green, .blue, .yellow').addClass('simonMove');
    clearInterval(counting);
  }

  $('.gameoff').toggleClass('switch');
  $('.gameon').toggleClass('switch');

  if (play) {
    reset();
  } else {
    play = true;
    begin();
  }
});

function reset() {
  moveCount = 1;
  moves = [];
  play = false;
  newGame = true;
  strict = false;
  $('.moves').val('');
  $('.start').removeClass('clicked');
  $('.strict').removeClass('clicked');
}

$('.btn').click(function() {
  if (this.id == 'strict') {
    $(this).toggleClass('clicked');
    if (strict) {
      strict = false;
    } else {
      strict = true;
    }
  }
  if (this.id == 'start') {
    if (play) {
      $(this).addClass('clicked');
      moves = [];
      moveCount = 1;
      playerMove = false;
      timer = 1100;
      lit = 400;
      rate = 1;
      $('.moves').val('1');
      setMoves();
    }
    if (play && moves.length < 1) {
      $.each(colors, function() {
        $('.' + this + '').removeClass('lit');
      });
      setMoves();
    }
  }
});

function startNew() {
  moves = [];
}

function setMoves() {
  setColor = Math.round(Math.random() * 3);
  if (moves[setColor] == moves[setColor - 1] && moves[setColor] == moves[setColor - 2] && moves[setColor] == moves[setColor - 3]) {
    if (setColor > 0) {
      moves.push(colors[setColor - 1]);
    } else {
      moves.push(colors[setColor + 1]);
    }
  } else {
    moves.push(colors[setColor]);
  }
  simonMove();
}

function begin() {
  var i = 0;
  newGame = false;
  (function loop() {
    litColor(colors[i]);
    if (++i < colors.length) {
      setTimeout(loop, 500);
    }
  })();
}

function simonMove() {
  clearInterval(counting);
  slow = 3;
  if (moveCount % 3 === 0 && timer > 300 && speedReset) {
    speedReset = false;
    timers();
  }
  var i = 0;
  (function loop() {
    litColor(moves[i]);

    if (++i < moveCount) {

      setTimeout(loop, timer);
    } else {
      playerMove = true;
      $('.red, .yellow, .green, .blue').removeClass('simonMove');
      // counting = setInterval(slowMove, 1000);
      counting = setInterval(function() {
        slowMove(slow, "SimonMove");
        slow -= 1;
      }, 1000);
    }
    $('.moves').val(moveCount);
  })();
}

function litColor(id) {
  $('.' + id + '').addClass('lit');
  playNote(id + "Note");
  setTimeout(function() {
    unlit(id);
  }, lit);
}

function unlit(id) {
  $('.' + id + '').removeClass('lit');
}

function playNote(id) {
  var sound = document.getElementById(id);
  sound.playbackRate = rate;
  sound.play();
}

function timers() {
  rate += 0.1;
  timer -= 100;
  lit -= 35;
}
            
          
!
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