cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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.

            
              <div class="container-fluid">
  <div class="row text-center">

    <div class="col-md-12">
      <div class="header">
        <h1>Simon<sup>®</sup></h1>
        <div class="modes">

          <label class="switch">
        <span class = "strict">strict</span>    
  <input type="checkbox" id="strictmode">
  <div class="slider round"></div>
      </label>

        </div>
      </div>
    </div>
  </div>

  <div class="row text-center">

    <div class="col-md-12">

      <div class="game">

        <figure>

          <div class="color green" id="green"></div>
          <div class="color red" id="red"></div>
          <div class="color yellow" id="yellow"></div>
          <div class="color blue" id="blue"></div>
          <figcaption class="info"><span id="start">start</span></figcaption>

        </figure>

      </div>

    </div>

  </div>

</div>
            
          
!
            
              @red: #F93B47;
@blue: #317FEE;
@yellow: #FFCE44;
@green: #13BA6A;
@redhighlight: #ff878e;
@yellowhighlight: #ffe291;
@bluehighlight: #8cbaff;
@greenhighlight: #00ed7b;

body {
  background: #f0f0f0;
  font-size: 28px;
  font-family: 'Archivo Black', sans-serif;
  color: #000;
}
h1{
  font-size: 60px;
}
.header{
  background: white;
  width: 300px;
  display: inline-block;
  margin: 25px 0 0 10px;
  padding: 20px;
 border-radius: 10%;
}
.modes{
  font-size: 22px;
   margin-right: 80px;
  cursor: pointer;
  
}
.game {
  margin: 200px;
}

* {
  box-sizing: border-box
}

figure {
  position: relative;
  width: 250px;
  height: 250px;
  border-radius: 50%;
  border: 2px solid transparent;
  margin: 40px auto;
  overflow: hidden;
  background: white;
  box-shadow: 0 0 6px 1px #000;
  transform: rotate(45deg) scale(2.2, 2.2)
}

.color {
  width: 123px;
  height: 125px;
  position: relative;
  float: left;
  background: #000;
  transform-origin: 100% 100%;
  box-shadow: inset 0 0 1px 0px rgb(187, 187, 187);
  background: @green;
  cursor: pointer;
}

.color:nth-of-type(2) {
  right: 0;
  background: @red;
}

.color:nth-of-type(3) {
  bottom: 0;
  left: 0;
  background: @yellow;
}

.color:last-of-type {
  right: 0;
  bottom: 0;
  background: @blue;
}

.greenHighlight {
  width: 123px;
  height: 125px;
  position: relative;
  float: left;
  background: #000;
  transform-origin: 100% 100%;
  transition:  .3s ease;
  box-shadow: inset 0 0 1px 0px rgb(187, 187, 187);
  background: @greenhighlight;
  cursor: pointer;
}

.redHighlight:nth-of-type(2) {
  right: 0;
  background: @redhighlight;
}

.yellowHighlight:nth-of-type(3) {
  bottom: 0;
  left: 0;
  background: @yellowhighlight;
}

.blueHighlight:last-of-type {
  right: 0;
  bottom: 0;
  background: @bluehighlight;
}
.info  {
  box-shadow: 0 0 11px 2px #000, 0 0 0px 32px rgba(255, 255, 255, 0.1);
  width: 100px;
  height: 100px;
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  text-align: center;
  line-height: 90px;
  margin: -50px 0 0 -50px;
  border: 4px solid white;
  transform: rotate(-45deg);
  background: #fff;
  
}

#start {
  cursor: pointer;
  font-size: 20px;
  display: block;
}

#no {
  padding-top: 25px;
  line-height: 20px;
  font-size: 20px;
  display: block;
}

// Slider styling from w3
// The box around the slider

.switch {
  position: relative;
  display: inline-block;
  width: 55px;
  height: 30px;
  margin: 10px;
}

.strict {
  margin-left: 70px;
}


// Hide HTML checkbox

.switch input {
  display: none;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .slider {
  background-color: #2196F3;
}

input:focus + .slider {
  box-shadow: 0 0 1px #2196F3;
}

input:checked + .slider:before {
  -webkit-transform: translateX(22px);
  -ms-transform: translateX(22px);
  transform: translateX(22px);
}

// Round sliders

.slider.round {
  border-radius: 22px;
}

.slider.round:before {
  border-radius: 50%;
}
            
          
!
            
              $(document).ready(function() {

  var game = {
    round: 0,
    count: 0,
    turn: false,
    colors: ['#red', '#green', '#blue', '#yellow'],
    sequence: [],
    sound: {
      blue: new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3'),
      red: new Audio('https://s3.amazonaws.com/freecodecamp/simonSound2.mp3'),
      yellow: new Audio('https://s3.amazonaws.com/freecodecamp/simonSound3.mp3'),
      green: new Audio('https://s3.amazonaws.com/freecodecamp/simonSound4.mp3')
    },
    strict: false
  };

  function clearGame() {
    game.sequence = [];
    game.round = 0;
    game.count = 0;
    game.turn = false;
    setTimeout(function() {
      $('.info').html('<span id ="start">start</span>');
    }, 2000);
  }

  function generateSequence() {
    var random = Math.floor((Math.random() * 4));
    var nextColor = game.colors[random];
    game.sequence.push(nextColor);
  }

  function computerGo() {
    var intervalID = setInterval(function() {
      var id = $(game.sequence[game.count]);
      var color = game.sequence[game.count].slice(1);
      var highlight = color + "Highlight";
      var sound = game.sound[color];
      sound.play();
      id.removeClass(color).addClass(highlight);
      setTimeout(function() {
        id.removeClass(highlight).addClass(color);
      }, 500);
      //If the current round count equals the round, 
        //that means the round is complete
      if (game.count == game.round) {
        console.log("end of computer round");
        game.count = 0;
        game.turn = true;
        $('.info').css("color","#000").animate({fontSize: "42px"}, function(){ $('.info').animate({fontSize: "28px"}) });
        clearInterval(intervalID);
      } else {
        //Else, increment the count and keep going
        ++game.count;
      }
    }, 1000);

  }

 
  $('.color').click(function() {
    //If game turn is true, then highlight and play sounds on click
    if (game.turn) {
      var circle = $(this);
      var id = this.id;
      var highlight = id + "Highlight";
      circle.removeClass(id).addClass(highlight);
      var sound = game.sound[id];
      sound.play();
      setTimeout(function() {
        circle.removeClass(highlight).addClass(id);
      }, 500);
      //Check that each click matches the computer's sequence
      if ("#" + id != (game.sequence[game.count])) {
        //If it doesn't, and we're in strict mode, Game Over
        if (game.strict) {
          console.log("Game over!");
          $('.info').html("<span id ='no'>Game over</span>");
          clearGame();
          return;
        //Else if we're not in strict mode, reset the count, set person turn 
          //to false, don't increment the round, and call the 
          //computer function which will repeat the current round
        } else {
          game.count = 0;
          game.turn = false;
          console.log("Try again");
          $('.info').html("<span id ='no'>Try again</span>");
          setTimeout(function() {
            $('.info').text(game.round + 1).css("color","#F93B47");
            computerGo();
          }, 1000);
          return;
        }
      }
      //If the count is equal to the round, the person has gotten to the 
       //end of the round without a mistake
      if (game.count == game.round) {
        console.log("End of person round.");
       //If the round is 19, the game is won
        if (game.round === 19) {
          console.log("You win! Game over.");
          $('.info').html("Win!");
          setTimeout(function() {
          clearGame();
             }, 2000);
          return;
        }
        game.count = 0;
        ++game.round;
        game.turn = false;
        generateSequence();
        setTimeout(function() {
          $('.info').html(game.round + 1).css("color","#F93B47");
          computerGo();

        }, 1000);
        console.log(game.sequence);
        //Else if it's not the end of the round, increment count
      } else {
        ++game.count;
      }
    }
  }); // EO playerMove

  $('.info').on('click', '#start', function() {
    generateSequence();
    computerGo();
    $('.info').html(game.round + 1).css("color","#F93B47");
  });
  
  $('#strictmode').click(function() {
    if (!game.strict) {
      game.strict = true;
    } else {
      game.strict = false;
    }
  });

}); //end of document
            
          
!
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