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 class='overlay'>
      <div class='inlay welcome'>
        <h1>Simon</h1>
        <h3>Instructions:</h3>
        <p>Think fast... SIMON says, "Chase my flashing lights and sounds"!</p>
        <p>The challenge is to repeat the ever increasing random signals the SIMON generates.</p>
        <p>There are four game difficulties available.</p>
        <ol>
          <li>easy mode: repeat 10 steps, if you make a mistake SIMON will repeat the pattern.</li>
          <li>normal mode: repeat 20 steps, again SIMON will repeat if you make a mistake.</li>
          <li>strict mode: repeat 35 steps, from here on SIMON will not accept mistakes.</li>
          <li>insane mode: repeat 50 steps with no errors. Can you do it?</li>
        </ol>
        <p>Press (re)start to begin, and again to reset the game. The window will display your current number of steps to repeat and difficulty level.</p>
        <p>Change difficulty using the slider switch, WARNING: this will also reset the current game.</p>
        <p>After winning or losing, before restarting SIMON, you can play back your last successful streak and also you longest streak yet.</p>
        <div class='overlaybutton'>Let's Play!</div>
      </div>
    </div>
    <div class='container'>
      <div class='buttonring'>
        <div class='button red'></div>
        <div class='button blue'></div>
        <div class='button green'></div>
        <div class='button yellow'></div>
        <div class='center'>
          <div class='centerlogo'>
            <h1 class='mb'>M<span class='bluetext'>B</span><span class='registered'>&reg;</span></h1>
            <h2 class='miltonbradley'>milton bradley</h2>
          </div>
        </div>
      </div>
      <div class='lowerbody'>
        <div class='lowerbodyinside'>
          <div class='buttonbox'>
            <div class='littlebutton last blue'>
              <span class='lasttext'>last</span>
            </div>
            <div class='littlebutton start red'>
              <span class='starttext'>(re)start</span>
            </div>
            <div class='littlebutton longest blue'>
              <span class='longesttext'>longest</span>
            </div>
            <div class='counterwindow'>
              <span class='difficultydisplay'></span>
              <span class='countdigits'></span>
            </div>
            <div class='levelslider'>
              <span class='leveltitle'>difficulty</span>
              <div class='sliderswitch'>
                <div class='sliderswitchgroove'></div>
                <div class='sliderswitchgroove'></div>
                <div class='sliderswitchgroove'></div>
              </div>
              <ul class='levelnumbers'>
                <li>1</li>
                <li>2</li>
                <li>3</li>
                <li>4</li>
              </ul>
            </div>
          </div>
          <div class='lowerlogo'>
            <h1 class='pocket'>Pocket</h1>
            <h2 class='simon'>Simon<span class='registered'>&reg;</span></h2>
          </div>
        </div>
      </div>
    </div>
            
          
!
            
              *{
  margin: 0;
}
body{
  color: hsla(266,10%,17%,1);
  font-variant: small-caps;
}
div{
  position: relative;
  box-sizing: border-box;
}
.overlay{
  position: absolute;
  height: 100%;
  min-height: fit-content;
  width: 100%;
  z-index: 9999;
}
.inlay{
  margin: 0 auto;
  padding: 40px 20px;
  width: 400px;
  height: 100%;
  border: 2px solid hsla(266,10%,90%,.9);
  background-color: hsla(266,10%,90%,.9);
}
.overlaybutton{
  width: 50%;
  height: 30px;
  margin: 10px auto;
  font-size: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: hsla(245,24%,16%,1);
  background-color: hsla(245,46%,76%,1);
}
.overlaybutton:hover{
  background-color: hsla(245,46%,56%,1);
}
.container{
  top: 20px;
  width: 400px;
  box-sizing: content-box;
  margin: auto;
}
.red{
  background-color: hsla(0,66%,46%,1);
}
.red.bright{
  background-color: hsla(0,100%,59%,1);
}
.blue{
  background-color: hsla(245,66%,46%,1);
}
.blue.bright{
  background-color: hsla(245,100%,59%,1);
}
.bluetext{
  color: hsla(245,66%,46%,1);
}
.green{
  background-color: hsla(119,66%,46%,1);
}
.green.bright{
  background-color: hsla(119,100%,59%,1);
}
.yellow{
  background-color: hsla(64,66%,46%,1);
}
.yellow.bright{
  background-color: hsla(64,100%,59%,1);
}
.buttonring{
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background-color: hsla(266,10%,17%,1);
  z-index: 600;
}
.button{
  position: absolute;
  width: 192px;
  height: 192px;
  border: 10px solid hsla(266,10%,17%,1);
  transition-property: background-color;
  transition-duration: .2s;
  transition-timing-function: linear;
}
.button.red{
  top: 8px;
  left: 8px;
  border-top-left-radius: 100%;
}
.button.blue{
  top: 8px;
  right: 8px;
  border-top-right-radius: 100%;
}
.button.green{
  bottom: 8px;
  left: 8px;
  border-bottom-left-radius: 100%;
}
.button.yellow{
  bottom: 8px;
  right: 8px;
  border-bottom-right-radius: 100%;
}
.center{
  position: absolute;
  top: 106px;
  left: 106px;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  border: 20px solid hsla(266,10%,17%,1);
  background-color: hsla(183,10%,70%,1);
}
.centerlogo{
  top: 14px;
  left: 14px;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  border: 2px solid hsla(266,10%,17%,1);
  background-color: hsla(183,10%,70%,1);
  text-align: center;
}
.mb{
  margin: 16px 0 0 8px;
  font-size: 50px;
  color: hsla(0,66%,46%,1);
}
.miltonbradley{
  margin-top: -10px;
  font-size: 14px;
}
.mb > .registered{
  position: relative;
  top: 2px;
  left: -2px;
  font-size: 12px;
  color: hsla(266,10%,17%,1);
}
.lowerbody{
  top: -130px;
  width: 330px;
  height: 400px;
  margin: auto;
  border-radius: 12%;
  background-color: hsla(266,10%,17%,1);
}
.lowerbodyinside{
  position: absolute;
  left: 20px;
  bottom: 20px;
  width: 290px;
  height: 360px;
  border-radius: 20px;
  border: 7px solid hsla(183,10%,70%,1);
  background-color: hsla(266,10%,17%,1);
}
.buttonbox{
  top: 36px;
  left: 4px;
  width: 268px;
  height: 200px;
  border-radius: 10px;
  background-color: hsla(183,10%,70%,1);
}
.littlebutton{
  position: absolute;
  top: 90px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 4px solid hsla(266,10%,17%,1);
}
.littlebutton.last{
  left: 40px;
}
.littlebutton.start{
  left: 114px;
}
.littlebutton.longest{
  left: 188px;
}
.lasttext,.starttext,.longesttext{
  position: absolute;
  top: -22px;
  font-size: 14px;
  font-weight: bold;
}
.lasttext{
  left: 2px;
}
.starttext{
  left: -13px;
}
.longesttext{
  left: -8px;
}
.counterwindow{
  position: absolute;
  left: 32px;
  bottom: 16px;
  height: 40px;
  width: 80px;
  border-radius: 4px;
  border: 2px solid hsla(360,33%,11%,1);
  background-color: hsla(360,33%,22%,1);
  color: hsla(360,66%,50%,1);
  text-align: center;
}
.countdigits,.difficultydisplay{
  position: relative;
  display: block;
}
.countdigits{
  top: -8px;
  font-size: 26px;
}
.difficultydisplay{
  top: -2px;
  font-size: 14px;
  color: hsla(94,100%,50%,1);
}
.levelslider{
  position: absolute;
  right: 12px;
  bottom: 21px;
  height: 30px;
  width: 100px;
  border-radius: 4px;
  border: 2px solid hsla(266,10%,17%,1);
  background-color: hsla(266,10%,32%,1);
}
.levelnumbers{
  position: absolute;
  top: 28px;
  width: 100px;
  padding: 0;
  list-style: none;
}
.leveltitle{
  position: absolute;
  top: -20px;
  width: 100px;
  text-align: center;
}
.levelnumbers li{
  margin-left: 11px;
  font-size: 14px;
  display: inline;
}
.sliderswitch{
  position: relative;
  left: 0px;
  height: 26px;
  width: 31px;
  padding: 0 5px;
  border-radius: 2px;
  background-color: hsla(266,10%,17%,1);
  transition: left .4s ease-in-out;
}
.sliderswitchgroove{
  margin: 2px auto;
  height: 22px;
  width: 4px;
  border-radius: 2px;
  background-color: hsla(266,10%,26%,1);
  display: inline-block;
}
.lowerlogo{
  position: absolute;
  bottom: 4px;
  left: 4px;
  width: 268px;
  height: 100px;
  border-radius: 10px;
  border: 2px solid hsla(183,10%,70%,1);
  text-align: center;
  color: hsla(183,10%,70%,1);
}
.pocket{
  font-size: 40px;
}
.simon{
  margin: -34px 0 0 4px;
  font-size: 80px;
}
.simon > .registered{
  position: relative;
  top: 2px;
  left: -2px;
  font-size: 16px;
}

            
          
!
            
              // Simon
// Written By Rob J Loranger
// February 2016
// Version 1.0.10
//
// Original game copyright 1978 Milton Bradley
// Currently owned by Hasbro
// By Ralph H. Baer and Howard j. Morrison and
// software by Lenny Cope
//
// The MIT License (MIT)
//
// Copyright (c) 2016 rob j loranger
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
//
// Begin audio oscillators
//

var audioCtx;
if (window.AudioContext){
  audioCtx = new window.AudioContext();
}else if(window.webkitAudioContext){
  audioCtx = new window.webkitAudioContext();
}
var redOsc = audioCtx.createOscillator(), blueOsc = audioCtx.createOscillator(), greenOsc = audioCtx.createOscillator(), yellowOsc = audioCtx.createOscillator(), razzOsc = audioCtx.createOscillator(), gainNode = audioCtx.createGain();
gainNode.connect(audioCtx.destination);
redOsc.frequency.value = 310;
redOsc.type = 'sine';
blueOsc.type = 'sine';
greenOsc.type = 'sine';
yellowOsc.type = 'sine';
razzOsc.type = 'square';
blueOsc.frequency.value = 209;
greenOsc.frequency.value = 415;
yellowOsc.frequency.value = 252;
razzOsc.frequency.value = 40;
redOsc.start();
blueOsc.start();
greenOsc.start();
yellowOsc.start();
razzOsc.start();
//
// Begin synth function
//
function synth(color,length){
  if(color === 'red'){
    redOsc.connect(gainNode);
    gainNode.gain.value = 0.23;
    setTimeout(function(){
      gainNode.gain.value = 0;
      redOsc.disconnect();
    }, length);
  }else if(color === 'blue'){
    blueOsc.connect(gainNode);
    gainNode.gain.value = 0.23;
    setTimeout(function(){
      gainNode.gain.value = 0;
      blueOsc.disconnect();
    }, length);
  }else if(color === 'green'){
    greenOsc.connect(gainNode);
    gainNode.gain.value = 0.23;
    setTimeout(function(){
      gainNode.gain.value = 0;
      greenOsc.disconnect();
    }, length);
  }else if(color === 'yellow'){
    yellowOsc.connect(gainNode);
    gainNode.gain.value = 0.23;
    setTimeout(function(){
      gainNode.gain.value = 0;
      yellowOsc.disconnect();
    }, length);
  }else if(color === 'razz'){
    razzOsc.connect(gainNode);
    gainNode.gain.value = 0.3;
    setTimeout(function(){
      gainNode.gain.value = 0;
    },length-200 );
    setTimeout(function(){
      gainNode.gain.value = 0.35;
    }, length-200);
    setTimeout(function(){
      gainNode.gain.value = 0;
      razzOsc.disconnect();
    }, length);
  }
}
//
// Begin simon game instance
//
var simon = {
  option: {
    difficulty: 1,
    speed: 700,
    level: 0,
  },
  pattern: {
    simon: [],
    player: [],
    playerRecent: [],
    playerLongest: []
  },
  says: {
    generate: function(){
      var rndNum = Math.floor(Math.random()*4)+1,
        nextColor;
      switch (rndNum){
        case 1:
          nextColor = 'red';
          break;
        case 2:
          nextColor = 'blue';
          break;
        case 3:
          nextColor = 'green';
          break;
        case 4:
          nextColor = 'yellow';
          break;
        default:
          nextColor = 'blue';
      }
      simon.pattern.simon.push(nextColor);
      simon.option.level++;
      simon.says.updateGame();
      simon.says.play(simon.pattern.simon);
    },
    play: function(pattern){
      var patternLength = pattern.length, ourCount = 0;
      var playing = setInterval(function(){
        if(ourCount < patternLength){
          var color = pattern[ourCount], identifier = document.querySelector('.button.'+color);
          identifier.classList.toggle('bright');
          synth(color,250);
          setTimeout(function(){
            identifier.classList.toggle('bright');
          },200);
          ourCount++;
        }else{
          clearInterval(playing);
        }
      },simon.option.speed);
    },
    replay: function(sequence){
      if((simon.option.level === 10 && simon.option.difficulty === 1) || (simon.option.level === 20 && simon.option.difficulty === 2) || (simon.option.level === 35 && simon.option.difficulty === 3) || (simon.option.level === 50 && simon.option.difficlty === 4)){
        if(sequence === 'last'){
          simon.says.play(simon.pattern.playerLast);
        }else if(sequence === 'longest'){
          simon.says.play(simon.pattern.playerLongest);
       }
      }
    },
    updateGame: function(){
      var digitsDisplay = document.querySelector('.countdigits');
      var digits = simon.option.level;
      if(simon.option.level === 0){
        digits = '- -';
      }else if(simon.option.level < 10){
        digits = '0'+digits;
      }
      digitsDisplay.innerHTML = digits;
      if(simon.option.level === 1){
        var difficultyDisplay = document.querySelector('.difficultydisplay');
        switch (simon.option.difficulty){
          case 1:
            difficultyDisplay.innerHTML = 'easy';
            break;
          case 2:
            difficultyDisplay.innerHTML = 'normal';
            break;
          case 3:
            difficultyDisplay.innerHTML = 'strict';
            break;
          case 4:
            difficultyDisplay.innerHTML = 'insane';
            break;
        }
      }
      if(simon.option.level === 5){
        simon.option.speed = 550;
      }
      if(simon.option.level === 14){
        simon.option.speed = 450;
      }
      if(simon.option.level === 25){
        simon.option.speed = 350;
      }
      if(simon.option.level === 37){
        simon.option.speed = 275;
      }
    },
    makeMove: function(color){
      simon.pattern.player.push(color);
      var position= simon.pattern.player.length - 1, identifier = document.querySelector('.button.'+color);
      if(simon.pattern.player.length < 1){
        position = 0;
      }
      identifier.classList.toggle('bright');
      synth(color,250);
      setTimeout(function(){
        identifier.classList.toggle('bright');
      },200);
      if(color !== simon.pattern.simon[position]){
        if(simon.option.difficulty < 3){
          synth('razz',400);
          simon.pattern.player = [];
          setTimeout(function(){
            simon.says.play(simon.pattern.simon);
          },800);
        }else{
          synth('razz',600);
          setTimeout(simon.says.youLose, 1200);
        }
      }else if(simon.pattern.simon.length === position + 1){
        simon.pattern.playerRecent = simon.pattern.player;
        if(simon.pattern.playerRecent.length > simon.pattern.playerLongest.length){
          simon.pattern.playerLongest = simon.pattern.playerRecent;
        }
        simon.pattern.player = [];
        if((simon.option.level === 10 && simon.option.difficulty === 1) || (simon.option.level === 20 && simon.option.difficulty === 2) || (simon.option.level === 35 && simon.option.difficulty === 3) || (simon.option.level === 50 && simon.option.difficlty === 4)){
          simon.says.youWin();
        }else{
          setTimeout(simon.says.generate,800);
        }
      }
    },
    youLose: function(){
      var sorryMessage = "<h2>Sorry you lost, you almost made it to "+ simon.option.level + " steps.</h2><div class='overlaybutton'>Play Again!</div>";
      document.querySelector('.overlay > .inlay').innerHTML = sorryMessage;
      document.querySelector('.overlay').style.display = 'block';
      document.querySelector('.overlaybutton').addEventListener('click', function(){
        this.parentNode.parentNode.style.display = 'none';
      });
    },
    youWin: function(){
      var winMessage = "<h2>You won!</h2><p>You completed " +simon.option.level+ " steps.</p><div class='overlaybutton'>Play Some More!</div>";
      document.querySelector('.overlay > .inlay').innerHTML = winMessage;
      document.querySelector('.overlay').style.display = 'block';
      document.querySelector('.overlaybutton').addEventListener('click', function(){
        this.parentNode.parentNode.style.display = 'none';
      });
    },
    reset: function(){
      simon.option.level = 0;
      simon.option.speed = 700;
      simon.says.updateGame();
      simon.pattern.simon = [];
      simon.pattern.player = [];
      simon.pattern.playerRecent = [];
      setTimeout(simon.says.generate,800);
    }
  }
};
document.querySelector('.overlaybutton').addEventListener('click', function(){
  this.parentNode.parentNode.style.display = 'none';
});
document.querySelector('.littlebutton.last').addEventListener('click', function(){
  simon.says.play(simon.pattern.playerRecent);
});
document.querySelector('.littlebutton.start').addEventListener('click', function(){
  if(simon.option.level === 0){
    simon.says.generate();
  }else{
    simon.says.reset();
  }
});
document.querySelector('.littlebutton.longest').addEventListener('click', function(){
  simon.says.play(simon.pattern.playerLongest);
});
document.querySelector('.sliderswitch').addEventListener('click', function(){
  switch (simon.option.difficulty){
    case 1:
      this.style.left = '20px';
      simon.option.difficulty = 2;
      simon.says.reset();
      break;
    case 2:
      this.style.left = '42px';
      simon.option.difficulty = 3;
      simon.says.reset();
      break;
    case 3:
      this.style.left = '66px';
      simon.option.difficulty = 4;
      simon.says.reset();
      break;
    default:
      this.style.left = '0px';
      simon.option.difficulty = 1;
      simon.says.reset();
  }
});
document.querySelector('.button.red').addEventListener('click', function(){
  simon.says.makeMove('red');
});
document.querySelector('.button.blue').addEventListener('click', function(){
  simon.says.makeMove('blue');
});
document.querySelector('.button.green').addEventListener('click', function(){
  simon.says.makeMove('green');
});
document.querySelector('.button.yellow').addEventListener('click', function(){
  simon.says.makeMove('yellow');
});

            
          
!
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