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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <div class="simon text-center">
  <div class="buttons">
    <div class="controls text-left">
      <h1 class="text-center">Simon <span class="r">®</span></h1>
      <div class="count inline left">
        <span class="level">--</span>
      </div>
      <div class="start inline left">
        <button></button>
      </div>
      <div class="strict inline left">
        <div class="strict-light"></div>
        <button></button>
      </div>
      <div class="titles"><span>COUNT</span><span>START</span> <span>STRICT</span></div>
      <div class="onOff text-center">
        <span class="off">OFF</span>
        <span class="on">ON</span>
        <div class="switch-box">
          <div class="switch"></div>
        </div>
      </div>
    </div>
    <div id="green" class="green"></div>
    <div id="red" class="red"></div>
    <div id="yellow" class="yellow"></div>
    <div id="blue" class="blue"></div>
  </div>
</div>
              
            
!

CSS

              
                .blue {
  background-color: #094a8f;
  border-bottom-right-radius: 400px;
}

.blue-turn {
  background-color: #1c8cff;
}

.buttons {
  height: 546px;
  padding-top: 27px;
  width: 600px;
}

.controls {
  background-color: #ece7ee;
  border: 20px solid #333;
  border-radius: 150px;
  height: 300px;
  margin: 120px 150px;
  position: absolute;
  width: 300px;
}

.controls h1 {
  font-family: Teko, sans-serif;
  font-size: 85px;
  padding-top: 25px;
}

.count {
  background-color: #32050c;
  border: 4px solid #333;
  border-radius: 10px;
  height: 50px;
  margin: -20px 0 0 30px;
  width: 80px;
}

.green {
  background-color: #00a74a;
  border-top-left-radius: 400px;
  margin-right: 20px;
}

.green,
.red,
.yellow,
.blue {
  display: inline-block;
  height: 260px;
  width: 260px;
}

.green-turn {
  background-color: #13ff7c;
}

.inline {
  display: inline-block;
}

.left {
  float: left;
}

.level {
  color: #430710;
  font-family: VT323, monospace;
  font-size: 40px;
  margin: -8px 0 0 18px;
  position: absolute;
}

.level-red {
  color: #dc0d29;
}

.level-win {
  margin-left: 3px !important;
}

.off {
  float: left;
}

.on {
  float: right;
}

.off,
.on {
  font-size: 12px;
  font-weight: 700;
  padding-top: 5px;
}

.onOff,
.pointer {
  cursor: pointer;
}

.onOff {
  width: 120px;
  height: 28px;
  margin: 10px auto 0 auto;
}

.r {
  font-size: 25px;
  margin: 20px 0 0 -3px;
  position: absolute;
}

.red {
  background-color: #9f0f17;
  border-top-right-radius: 400px;
}

.red-bg {
  background-color: #dc0d29 !important;
}

.red-turn {
  background-color: #ff4c4c;
}

.simon {
  background-color: #333;
  border-radius: 300px;
  height: 600px;
  margin: 10% auto;
  width: 600px;
}

.start {
  margin: -10px 20px 0;
}

.start button {
  background-color: #fc0102;
}

.start button,
.strict button {
  border: 3px solid #333;
  border-radius: 18px;
  height: 35px;
  outline: none;
  width: 35px;
}

.start button:active,
.strict button:active {
  border: 4px solid #333;
}

.strict {
  margin: -10px 10px 0 0;
}

.strict button {
  background-color: #ff0;
}

.strict-light {
  background-color: #32050c;
  border: 2px solid #333;
  border-radius: 6px;
  height: 12px;
  margin: -18px 0 0 11px;
  position: absolute;
  width: 12px;
}

.switch {
  background-color: #3193de;
  border-radius: 4px;
  height: 24px;
  width: 24px;
}

.switch-box {
  background-color: #222;
  border-radius: 4px;
  height: 28px;
  width: 60px;
  padding: 2px;
  margin: 0 auto;
}

.titles {
  font-weight: 700;
  margin: 42px 0 0 45px;
}

.titles span:first-child {
  margin-right: 30px;
}

.titles span:nth-child(2) {
  margin-right: 5px;
}

.yellow {
  background-color: #cca707;
  border-bottom-left-radius: 400px;
  margin: 20px 20px 0 0;
}

.yellow-turn {
  background-color: #fed93f;
}

body {
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  background-image: url("http://subtlepatterns2015.subtlepatterns.netdna-cdn.com/patterns/tileable_wood_texture.png");
  background-repeat: repeat;
  color: #000;
  cursor: default;
  user-select: none;
}

@media all and (max-width: 600px) {
  .simon {
    top: 40px;
    -moz-transform: scale(0.8);
    -ms-transform: scale(0.8);
    -o-transform: scale(0.8);
    -webkit-transform: scale(0.8);
    transform: scale(0.8);
    -o-transform-origin: 0 0;
    -ms-transform-origin: 0 0;
    -webkit-transform-origin: 0 0;
    -moz-transform-origin: 0 0;
    transform-origin: 0 0;
    margin-left: 20px;
  }
}

@media all and (max-width: 539px) {
  .simon {
    top: 20px;
    -moz-transform: scale(0.6);
    -ms-transform: scale(0.6);
    -o-transform: scale(0.6);
    -webkit-transform: scale(0.6);
    transform: scale(0.6);
    -o-transform-origin: 0 0;
    -ms-transform-origin: 0 0;
    -webkit-transform-origin: 0 0;
    -moz-transform-origin: 0 0;
    transform-origin: 0 0;
    margin-left: 10px;
  }
}
              
            
!

JS

              
                  $(document).ready(function() {
    var colors = ['green', 'red', 'yellow', 'blue'];
    var cpu = [];
    var human = [];
    var greenBeep = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3');
    var redBeep = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound2.mp3');
    var yellowBeep = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound3.mp3');
    var blueBeep = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound4.mp3');
    var failBeep = new Audio('http://www.soundjay.com/button/sounds/beep-05.mp3');
    var on = false;
    var humanClick = false;
    var user = false;
    var strict = false;
    var begin = true;
    var level = 1;
    var orderIndex = 0;
    var color = colors[Math.floor(Math.random() * colors.length)];
    var btnColor, currentColor;
    // strict light on/off.
    $('.strict').on('click', function() {
      if (on) {
        $('.strict-light').toggleClass('red-bg');
        if (!strict) {
          strict = true;
        } else {
          strict = false;
        }
      }
    });
    // master reset.
    function masterReset() {
      cpu = [];
      human = [];
      on = false;
      user = false;
      humanClick = false;
      begin = true;
      strict = false;
      begin = true;
      level = 1;
      orderIndex = 0;
      color = colors[Math.floor(Math.random() * colors.length)];
      btnColor = '';
      currentColor = '';
    }
    // strict reset.
    function strictReset() {
      cpu = [];
      human = [];
      user = false;
      begin = true;
      level = 1;
      orderIndex = 0;
      index = 0;
      btnColor = '';
      currentColor = '';
    }
    // beep sound.
    function beep(entry) {
      var beep = '';
      if (entry === 'green') {
        beep = greenBeep;
      } else if (entry === 'red') {
        beep = redBeep;
      } else if (entry === 'yellow') {
        beep = yellowBeep;
      } else {
        beep = blueBeep;
      }
      return beep.play();
    }
    // start animation and level.
    function start(text) {
      if (!on) {
        $(this).stop();
        return;
      }
      $('.level').fadeOut(0).delay(200).fadeIn(0).delay(200).fadeOut(0).delay(200).fadeIn(0).delay(500).queue(function() {
        $(this).html(text).dequeue();
      });
    };
    // selected button light up and relating beep sound.
    function button() {
      if (!on) {
        $(this).stop();
        return;
      }
      color = colors[Math.floor(Math.random() * colors.length)];
      cpu.push(color);
      cpuPlay();
    };
    // cpu play all buttons saved so far.
    function cpuPlay() {
      if (!on) {
        $(this).stop();
        return;
      }
      var cpuCurrent = cpu[orderIndex];
      setTimeout(function() {
        beep(cpuCurrent);
        $('#' + cpuCurrent).toggleClass(cpuCurrent + '-turn');
      }, 500);
      setTimeout(function() {
        $('#' + cpuCurrent).toggleClass(cpuCurrent + '-turn');
        if (cpu[orderIndex + 1] !== undefined) {
          orderIndex++;
          cpuPlay();
        } else {
          orderIndex = 0;
          user = true;
          humanClick = true;
          $('#green, #red, #yellow, #blue').addClass('pointer');
        }
      }, 1500);
    }
    // on/off switch.
    $('.onOff').on('click', function() {
      $('.level').toggleClass('level-red');
      if (on) {
        $('.switch').css('float', '');
        setTimeout(function() {
          $('.green, .red, .yellow, .blue').removeClass('pointer');
          humanClick = false;
        }, level * 1000);
        masterReset();
        $('.level').hide();
        setTimeout(function() {
          $('#green, #red, #yellow, #blue').removeClass('green-turn, red-turn, yellow-turn, blue-turn pointer');
          $('.level').html('--').show();
          $('.strict-light').removeClass('red-bg');
        }, 1000);
      } else {
        $('.switch').css('float', 'right');
        on = true;
      }
    });
    // start simon says trigger.
    $('.start').on('click', function() {
      if (!on) {
        return;
      }
      if (begin) {
        start('01');
        setTimeout(button, 2000);
        begin = false;
      } else {
        humanClick = false;
        setTimeout(function() {
          $('.green, .red, .yellow, .blue').removeClass('pointer');
          humanClick = false;
        }, level * 1000);
        masterReset();
        setTimeout(function() {
          $('#green, #red, #yellow, #blue').removeClass('green-turn, red-turn, yellow-turn, blue-turn pointer');
          $('.level').html('--');
          $('.strict-light').removeClass('red-bg');
          on = true;
          $('.start').click();
        }, 1000);
      }
    });
    // simon buttons click trigger.
    $('#green, #red, #yellow, #blue').on('click', function() {
      if (!on || !user || !humanClick) {
        return;
      }
      humanClick = false;
      btnColor = $(this)[0].id;
      human.push(btnColor.toString());
      currentColor = human[human.length - 1];
      if (human[orderIndex] === cpu[orderIndex]) {
        beep(currentColor);
      }
      $('#' + currentColor).toggleClass(currentColor + '-turn');
      setTimeout(function() {
        humanClick = true;
        $('#green, #red, #yellow, #blue').removeClass('pointer');
        $('#' + currentColor).toggleClass(currentColor + '-turn');
      }, 1000);
      user = false;
      if (level === 20 && cpu.length === human.length && human[orderIndex] === cpu[orderIndex]) {
        $('.level').html('WIN!').toggleClass('level-win');
        setTimeout(function() {
          $('.level').toggleClass('level-win').html('--');
          $('.start').click();
        }, 3000);
      } else if (cpu.length === human.length && human[orderIndex] === cpu[orderIndex]) {
        level++;
        $('.level').delay(1500).queue(function() {
          if (level < 10) {
            $(this).html('0' + level).toString();
          } else {
            $(this).html(level).toString();
          }
          $(this).dequeue();
        });
        setTimeout(button, 3000);
        human = [];
        if (orderIndex > 0) {
          orderIndex = 0;
        }
      } else if (human[orderIndex] === cpu[orderIndex]) {
        $('.' + human[orderIndex]).addClass(human[orderIndex] + '-turn');
        setTimeout(function() {
          $('.' + human[orderIndex]).removeClass(human[orderIndex] + '-turn');
          $('.green, .red, .yellow, .blue').addClass('pointer');
        }, 1000);
        user = true;
        orderIndex++;
      } else {
        human = [];
        orderIndex = 0;
        $('.level').html('!!');
        failBeep.play();
        start();
        if (strict) {
          setTimeout(function() {
            strictReset();
            $('.level').html('--');
            $('.start').click();
          }, 1500);
          setTimeout(function() {
            $('#green, #red, #yellow, #blue').removeClass('green-turn, red-turn, yellow-turn, blue-turn');
          }, 1600);
        } else {
          setTimeout(function() {
            if (level > 9) {
              $('.level').html(level);
            } else {
              $('.level').html('0' + level);
            }
            cpuPlay();
          }, 1500);
        }
      }
      console.log('human: ' + human);
      console.log('cpu: ' + cpu);
      console.log('index: ' + orderIndex);
    });
  }); // end doc ready.
              
            
!
999px

Console