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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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="outer-circle center-block">
  <div class="button left left-top-green"></div>
  <div class="button right right-top-red"></div>
  <div class="inner-circle center-block">
    <div class="simon">
      <p>Simon</p>
    </div>
    <div class="controls no-mouse form-inline">
      <input type="text" class="form-control count" value="" readonly/>
      <button type="button" name="start-btn" class="start btn control-btn btn-primary"></button>
      <button type="button" name="strict-btn" class="strict btn control-btn btn-primary"></button>
    </div>
    <div class="labels">
      <span class="count-label">count</span>
      <span class="start-label">start</span>
      <span class="strict-label">strict</span>
    </div>
    <div class="power-button">
      <button type="button" name="button" class="btn btn-power center-block">on</button>
    </div>
  </div>
  <div class="button left left-bottom-yellow"></div>
  <div class="button right right-bottom-blue"></div>
</div>

<audio class="audio-green" src="https://s3.amazonaws.com/freecodecamp/simonSound1.mp3" type="audio/mpeg" preload="auto"></audio>
<audio class="audio-red" src="https://s3.amazonaws.com/freecodecamp/simonSound2.mp3" type="audio/mpeg" preload="auto"></audio>
<audio class="audio-yellow" src="https://s3.amazonaws.com/freecodecamp/simonSound3.mp3" type="audio/mpeg" preload="auto"></audio>
<audio class="audio-blue" src="https://s3.amazonaws.com/freecodecamp/simonSound4.mp3" type="audio/mpeg" preload="auto"></audio>
            
          
!
            
              body {
  padding: 50px;
  background: url(https://dl.dropboxusercontent.com/u/21809793/seamless_paper_texture.png) repeat;
}
.outer-circle {
  position: relative;
  width: 500px;
  height: 500px;
  border-radius: 100%;
  border: 10px solid #333;
  overflow: hidden;
  z-index: 9;
}
.inner-circle {
  position: relative;
  top: 150px;
  width: 200px;
  height: 200px;
  border-radius: 100%;
  border: 10px solid #333;
  z-index: 10;
  background-color: #ECE7EE;
  text-align: center;
}
.simon {
  top: 12px;
  left: 30px;
  position: absolute;;
}
.inner-circle p {
  font-size: 42px;
  font-weight: 900;
  font-family: 'Alegreya', serif;
}
.button {
  position: relative;
  width: 240px;
  height: 240px;
  z-index: 1;
  touch-action: manipulation;
  cursor: pointer;
}
.left {
  float: left;
}
.right {
  float: right;
}
.no-mouse {
  pointer-events: none;
}
.left-top-green {
  background-color: #00A74A;
  border-right: 5px solid #333;
  border-bottom: 5px solid #333;
}

.right-top-red {
  background-color: #9F0F17;
  border-left: 5px solid #333;
  border-bottom: 5px solid #333;
}

.left-bottom-yellow {
  background-color: #CCA707;
  border-right: 5px solid #333;
  border-top: 5px solid #333;
}

.right-bottom-blue {
  background-color: #094A8F;
  border-left: 5px solid #333;
  border-top: 5px solid #333;
}
.controls {
  position: absolute;
  text-align: left;
  top: 65px;
  left: 28px;
}

.form-control.count:focus {
  outline: none;
}
.form-control:focus {
  box-shadow: none;
}
.form-control.count {
  width: 44px;
  display: inline-block;
  font-size: 14px;
  padding-left: 6px;
  padding-right: 6px;
  text-align: right;
  border: 2px solid #333;
  font-weight: 700;
}
.control-btn {
  width: 20px;
  height: 20px;
  margin-left: 12px;
  padding: 6px 6px;
  background-color: #CCA707;
  border: 2px solid #333;
  border-radius: 100%;
}

.strict-on,
.control-btn:hover,
.control-btn:active,
.control-btn:focus {
  background-color: #f7d756;
}
.labels {
  position: absolute;
  top: 98px;
  left: 30px;
  font-weight: 700;
}
.start-label {
  margin-left: 8px;
  margin-right: 5px;
}
.power-button {
  position: absolute;
  top: 125px;
  left: 65px;
  text-align: left;
}
.btn-power {
  border-radius: 10px;
  width: 50px;
  color: #FFF;
  font-weight: bold;
  background-color: #00A74A;
  border: 2px solid #333;
}
.btn:active,
.btn:focus,
.btn:hover {
  color: #FFF;
  outline: none;
}
.power-on {
  background-color: #9F0F17;
}

/*button presses*/
.green-press {
  background-color: #02c958;
}
.red-press {
  background-color: #ce3941;
}
.yellow-press {
  background-color: #f7d756;
}
.blue-press {
  background-color: #1f70c1;
}

            
          
!
            
              $(function() {
  var challenge = [];
  var count = 1;
  var numPresses = 0;
  var strict = 0;
  var timeouts = [];

  var game = {

    start: function start() {
      function randomPos() {
        challenge.push(Math.floor(Math.random() * (4 - 1 + 1)) + 1);
      }
      (function createChallenge() {
        for (var x = 0; x < 20; x++) {
          randomPos();
        }
      })();
    },
    displayChallenge: function displayChallenge() {
      this.displayCount();
      numPresses = 0;
      var challengeValue;
      for (var x = 0; x < count; x++) {
        challengeValue = challenge[x];
        timeouts.push(setTimeout(this.convertToButtonPress(challengeValue), 800 * x));
      }
      setTimeout(function() {
        game.enableButtons();
      }, 800 * count);
    },
    delayedDisplayChallenge: function delayedDisplayChallenge() {
      game.displayChallenge();
    },
    disableButtons: function disableButtons() {
      return $('.button').addClass('no-mouse');
    },

    enableButtons: function enableButtons() {
      return $('.button').removeClass('no-mouse');
    },
    convertToButtonPress: function convertToButtonPress(num) {
      if (num === 1) {
        return buttonPress.playGreen;
      }
      if (num === 2) {
        return buttonPress.playRed;
      }
      if (num === 3) {
        return buttonPress.playYellow;
      }
      if (num === 4) {
        return buttonPress.playBlue;
      }
    },
    displayCount: function displayCount() {
      $('.count').val(count);
    },
    strictStart: function strictStart() {
      if (!$('.strict').hasClass('strict-on')) {
        $('.strict').addClass('strict-on');
      }
      if ($('.start').hasClass('strict-on')) {
        $('.start').removeClass('strict-on');
      }
      challenge.length = 0;
      count = 1;
      strict = 1;
      game.start();
      game.displayChallenge();
    },
    checkPress: function checkPress(num) {
      if (num === challenge[numPresses]) {
        numPresses++;
        game.convertToButtonPress(num)();
        if (numPresses === count) {
          count++;
          if (count === 21) {
            buttonPress.displayWin();
            $('.count').val('WIN');
            game.disableButtons();
          } else {
            game.disableButtons();
            setTimeout(game.delayedDisplayChallenge, 1500);
          }
        }
      } else {
        if (strict === 1) {
          buttonPress.playError();
          $('.count').val('ERR');
          setTimeout(function() {
            game.strictStart();
          }, 2000);
        } else {
          buttonPress.playError();
          $('.count').val('ERR');
          setTimeout(game.delayedDisplayChallenge, 3000);
        }
      }
    },
    clearAllTimeouts: function() {
      timeouts.forEach(function(timer) {
        clearTimeout(timer);
      })
    }

  };

  var powerButton = {
    currentText: function currentText() {
      return $('.btn-power').text();
    },
    onText: "on",
    offText: "off",
    switchPower: function switchPower() {   
      if (this.currentText() === this.offText) {
        count = '';
        $('.btn-power').text(this.onText).toggleClass('power-on');
        $('.controls').addClass('no-mouse');
        if ($('.strict').hasClass('strict-on')) {
          $('.strict').removeClass('strict-on');
        }
        if ($('.start').hasClass('strict-on')) {
          $('.start').removeClass('strict-on');
        }   
        game.displayCount();
        game.disableButtons();
        game.clearAllTimeouts();

      } else {
        $('.btn-power').text(this.offText).toggleClass('power-on');
        $('.controls').removeClass('no-mouse');
      }
    }
  };

  var buttonPress = {
    playGreen: function playGreen() {
      $('.left-top-green').toggleClass('green-press');
      $('.audio-green')[0].play();
      setTimeout(function() {
        $('.left-top-green').toggleClass('green-press');
      }, 500);
    },
    playRed: function playRed() {
      $('.right-top-red').toggleClass('red-press');
      $('.audio-red')[0].play();
      setTimeout(function() {
        $('.right-top-red').toggleClass('red-press');
      }, 500);
    },
    playYellow: function playYellow() {
      $('.left-bottom-yellow').toggleClass('yellow-press');
      $('.audio-yellow')[0].play();
      setTimeout(function() {
        $('.left-bottom-yellow').toggleClass('yellow-press');
      }, 500);
    },
    playBlue: function playBlue() {
      $('.right-bottom-blue').toggleClass('blue-press');
      $('.audio-blue')[0].play();
      setTimeout(function() {
        $('.right-bottom-blue').toggleClass('blue-press');
      }, 500);
    },
    error: function error() {
      $('.left-top-green').toggleClass('green-press');
      $('.audio-green')[0].play();
      setTimeout(function() {
        $('.left-top-green').toggleClass('green-press');
      }, 500);
      $('.right-top-red').toggleClass('red-press');
      setTimeout(function() {
        $('.right-top-red').toggleClass('red-press');
      }, 500);
      $('.left-bottom-yellow').toggleClass('yellow-press');
      setTimeout(function() {
        $('.left-bottom-yellow').toggleClass('yellow-press');
      }, 500);
      $('.right-bottom-blue').toggleClass('blue-press');
      setTimeout(function() {
        $('.right-bottom-blue').toggleClass('blue-press');
      }, 500);
    },
    playError: function playError() {
      buttonPress.error();
      setTimeout(function() {
        buttonPress.error();
      }, 800);
      setTimeout(function() {
        buttonPress.error();
      }, 1600);
    },
    win: function win() {
      this.delayedPress(buttonPress.playGreen, 1);
      this.delayedPress(buttonPress.playRed, 2);
      this.delayedPress(buttonPress.playBlue, 3);
      this.delayedPress(buttonPress.playYellow, 4);
    },
    displayWin: function displayWin() {
      this.win();
      setTimeout(function() {
        buttonPress.win();
      }, 1500);
      setTimeout(function() {
        buttonPress.win();
      }, 2800);
    },
    delayedPress: function delayedPress(color, num) {
      setTimeout(function() {
        color();
      }, num * 300);
    }
  };

  $('.left-top-green').click(function() {
    game.checkPress(1);
  });

  $('.right-top-red').click(function() {
    game.checkPress(2);
  });

  $('.left-bottom-yellow').click(function() {
    game.checkPress(3);
  });

  $('.right-bottom-blue').click(function() {
    game.checkPress(4);
  });

  $('.btn-power').click(function() {
    powerButton.switchPower();
  });

  $('.start').click(function() {
    if ($('.strict').hasClass('strict-on')) {
      $('.strict').removeClass('strict-on');
    }
    if (!$('.start').hasClass('strict-on')) {
      $('.start').addClass('strict-on');
    }
    challenge.length = 0;
    count = 1;
    strict = 0;
    game.start();
    game.displayChallenge();
  });

  $('.strict').click(function() {
    game.strictStart();
  });

  game.disableButtons();

});
            
          
!
999px
Loading ..................

Console