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 = 'fluid-container'>
  <div class= 'wrap'>
    <div class = 'topdiv'>
      <div class = 'top green green-off inline push inactive' id = '4'></div>
      <div class='top red red-off inline push inactive' id ='1'></div>
    </div>
    <div class = 'bottomdiv'>
      <div class = 'bottom yellow yellow-off inline push inactive' id = '3'></div>
      
      <div class='bottom blue blue-off inline push inactive' id='2'></div>
    </div>
    <div class = 'center'>
      <div class ='brand'>SIMON<span class="small">®</span></div>
      <div class='row'>
        <div class = 'counter col-xs-5'><div class='screen off'><span id = 'val'>--</span></div><div class='text-count'>COUNTER</div></div> <div class='col-xs-3'><button class= 'start small-round'></button><div class='text'>START</div></div><div class='col-xs-3'><div class='strict-light light-off'></div><button class= 'small-round active strict'></button><div class='text'>STRICT</div></div>
      </div>
      <!--modified code from https://www.w3schools.com/howto/howto_css_switch.asp -->
      <div><span class='text'>OFF</span> <label class="switch">
  <input type="checkbox" class='onOff'>
  <div class="slider"></div>
        </label><span class='text'>ON</span></div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                /*color values and fonts taken from example pen*/
@import url('https://fonts.googleapis.com/css?family=Alfa+Slab+One|VT323|Oswald');
html {
  margin: 0;
  padding: 0;
  border: 0;
}
.fluid-container {
  background-color: #333;
  margin: auto;
  height: 475px;
  width: 475px;
  position: relative;
  top: 10vh;
  border-radius: 100%;
  text-align: center;
  
}
.wrap {
  position: relative;
 
  top: 30px;
}
.push {
  position: relative;
  height: 210px;
  width: 210px;
  background-color: gray;
  border: 12px solid #333;
}
.inactive {
  pointer-events: none;
}
.active {
  pointer-events: auto;
  cursor: pointer;
}

.inline {
  display: inline-block;
}
.topdiv, .bottomdiv {
  margin-bottom: -4px;
}

.green {

  border-top-left-radius: 100%;
  
}
.green-off{
    background-color: #00a74a;
}
.green-on{
  background-color : #13ff7c;
}
.yellow {
  
  border-bottom-left-radius: 100%;
}
.yellow-off {
  background-color: #cca707;
}
.yellow-on {
  background-color : #fed93f;
}
.red {
  
  border-top-right-radius: 100%;
  
}
.red-off {
  background-color: #9f0f17;
}
.red-on {
  background-color : #ff4c4c;
}
.blue {
  
  border-bottom-right-radius: 100%;
  
}
.blue-off {
  background-color: #094a8f;
}
.blue-on {
  background-color : #1c8cff;
}
.center {
  position: Absolute;
  background-color: AntiqueWhite;
  height: 220px;
  width: 220px;
  border-radius: 100%;
  top:50%;
  left:50%;
  margin: -112px 0 0  -112px;
  border: 12px solid #333;
}
.brand {
 font-family: 'Alfa Slab One', cursive; 
 font-size : 2.2em;
  margin-top : 35px;
}

.brand .small{
  font-size : 0.3em;
  position : relative;
  top : -20px;
}
.screen {
  font-family: 'VT323', monospace;
  width: 50px;
  padding : 0;
  background-color: #32050C;
  margin: auto;
  color: #DC0D29;
  font-size : 1.8em;
  border-radius: 10px;
}
.off {
  color: #32050C;
}
.on {
  color: #DC0D29;
}
.small-round {
  width : 25px;
  height : 25px;
  margin:auto;
  background-color: red;
  border-radius: 100%;
  border : 4px solid #444;
  box-shadow : 0px 2px 3px #222;
  position: relative;
  bottom: -10px;
  
}
.small-round:active {
  bottom: -11px;
  outline: none;
}
button:focus {outline:0;}
.strict-light {
  height: 10px;
  width: 10px;
  border-radius: 100%;
  margin: auto;
  border: 2px solid black;
  margin-top: -5px;
}
.light-off {
  background-color: black;
}
.light-on {
  background-color: red;
}
.strict {
  background-color: yellow;
  margin-top: -10px;
}
.text {
  margin-top: 10px;
  font-size: 10px;
  text-align: center;
}
.text-count {
  font-size: 10px;
}
/*modified code from https://www.w3schools.com/howto/howto_css_switch.asp*/
.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}
.switch input {display:none;}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #333;
  -webkit-transition: .4s;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: #3193DE;
  -webkit-transition: .4s;
  transition: .4s;
}



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

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

JS

              
                
$(document).ready(function() {

  var isOn = false,
    isStrict = false,
    playing = false,
    myArr = [],
    correct = false,
    seq, length, counter;
  var audio1 = new Howl({
    urls: ['https://s3.amazonaws.com/freecodecamp/simonSound1.mp3'],
    end: function() {
      audio1.stop();
    }

  });

  var audio2 = new Howl({
    urls: ['https://s3.amazonaws.com/freecodecamp/simonSound2.mp3'],
    onend: function() {
      audio2.stop();
    }

  });
  var audio3 = new Howl({
    urls: ['https://s3.amazonaws.com/freecodecamp/simonSound3.mp3'],
    onend: function() {
      audio3.stop();
    }

  });
  var audio4 = new Howl({
    urls: ['https://s3.amazonaws.com/freecodecamp/simonSound4.mp3'],
    onend: function() {
      audio4.stop();
    }

  });
  
  var length1 = audio1.duration * 1000,
    length2 = audio2.duration * 1000,
    length3 = audio3.duration * 1000,
    length4 = audio4.duration * 1000;

  function makeSequence() {
    var arr = [];
    for (var i = 0; i < 20; i++) {
      arr.push(Math.floor(Math.random() * 4) + 1);
    }
    return arr;
  }

  function reset(input) {
    setTimeout(function() {
      audio1.stop();
      audio2.stop();
      audio3.stop();
      audio4.stop();
    }, 200);
    length = 1;
    counter = 0;
    myArr = [];
    $('#1').addClass('red-off').removeClass('red-on');
    $('#2').addClass('blue-off').removeClass('blue-on');
    $('#3').addClass('yellow-off').removeClass('yellow-on');
    $('#4').addClass('green-off').removeClass('green-on');
    $('.push').addClass('inactive').removeClass('active');
    if (input === 'off') {
      seq = [];
      isStrict = false;
      playing = false;
      $('#val').text('--');
      $('.strict-light').addClass('light-off').removeClass('light-on');
    } else if (input === 'strict') {
      seq = makeSequence();
      console.log(seq);
    } else if (input === 'restart') {

    }
  }
  $('.onOff').change(function() {

    $('.screen').toggleClass('off on');
    isOn = !isOn;
    if (!isOn) {

      reset('off');
    }
  });

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

    if (isOn && !playing) {
      $('.strict-light').toggleClass('light-off light-on');
      isStrict = !isStrict;
    }
  });

  function lightUp(num, time) {
    switch (num) {
      case 1:

        $('#1').addClass('red-on').removeClass('red-off');
        audio1.play();
        setTimeout(function() {
          $('#1').addClass('red-off').removeClass('red-on');
        }, time);
        break;
      case 2:

        $('#2').addClass('blue-on').removeClass('blue-off');
        audio2.play();
        setTimeout(function() {
          $('#2').addClass('blue-off').removeClass('blue-on');
        }, time);
        break;
      case 3:

        $('#3').toggleClass('yellow-off yellow-on');
        audio3.play();
        setTimeout(function() {
          $('#3').toggleClass('yellow-off yellow-on');
        }, time);
        break;
      case 4:
        $('#4').toggleClass('green-off green-on');
        audio4.play();
        setTimeout(function() {
          $('#4').toggleClass('green-off green-on');
        }, time);
    }
  }
  //from 1000 and 
  function playSeq() {
    var i = 0;

    function loop() {
      var time = 1000 - ((length - 1) * 35);
      lightUp(seq[i], time);
      i++;
      if (i < length) {
        setTimeout(loop, time * 1.5);
      } else {
        setTimeout(function() {
        $('.push').toggleClass('inactive active');
        }, time);
        counter = 0;
      }

    }
    loop();

  }

  function updateCounter(num) {
    if (num < 10) {
      $('#val').text('0' + num);
    } else {
      $('#val').text(num);
    }
  }

  function flash() {
    var time = setInterval(function() {
      $(".screen").toggleClass('on off');
    }, 200);
    setTimeout(function() {
      clearInterval(time);
      $(".screen").addClass('on').removeClass('off');
      updateCounter(length);
    }, 1200);
  }

  function error() {
    audio1.play();
    audio2.play();
    audio3.play();
    audio4.play();
    $('#val').text('!!');
    flash();

  }
  $('.start').click(function() {
    if (isOn) {
      if (!playing) {
        seq = makeSequence();
        playing = true;
      }
      playing = true;
      reset('restart');
      flash();
      setTimeout(function() {
        playSeq();
      }, 1200);
    }
  });
  $('.push').click(function() {
    var val = parseInt($(this).attr('id'));
    if (val === seq[counter]) {
      myArr.push(val);
      counter = counter + 1;
      if (myArr.length === length) {
        $('.push').toggleClass('inactive active');
        if (length === 2) {
          $('#val').text('**');

          var time = setInterval(function() {
            $(".screen").toggleClass('on off');
          }, 200);
          setTimeout(function() {
            clearInterval(time);
          }, 1200);
          reset('strict');
          setTimeout(function() {
            updateCounter(length);
            playSeq();
          }, 1500);
        } else {
          myArr = [];
          length = length + 1;
          correct = true;

        }
      }
    } else if (!isStrict) {

      $('.push').toggleClass('inactive active');
      error();
      myArr = [];
      setTimeout(function() {

        playSeq();
      }, 1300);

    } else {

      reset('strict');
      error();
      setTimeout(function() {
        console.log('seq');
        playSeq();
      }, 1300);
    }
  });
  var timeout;
  $('.push').mousedown(function() {
    audio1.stop();
    audio2.stop();
    audio3.stop();
    audio4.stop();
    var num = $(this).attr('id');
    switch (num) {
      case '1':
        $('#1').toggleClass('red-on red-off');
        audio1.play();
        break;
      case '2':
        $('#2').toggleClass('blue-on blue-off');
        audio2.play();
        break;
      case '3':
        $('#3').toggleClass('yellow-off yellow-on');
        audio3.play();
        break;
      case '4':
        $('#4').toggleClass('green-off green-on');
        audio4.play();
    }
    timeout = setInterval(function() {
      var num = $(this).attr('id');
      switch (num) {
        case 1:
          $('#1').toggleClass('red-off red-on');
          break;
        case 2:
          $('#2').toggleClass('blue-off blue-on');
          break;
        case 3:
          $('#3').toggleClass('yellow-off yellow-on');
          break;
        case 4:
          $('#4').toggleClass('green-off green-on');

      }
    }, 500);

    return false;
  });
  $('.push').mouseup(function() {
    var num = $(this).attr('id');
    switch (num) {
      case '1':
        $('#1').addClass('red-off').removeClass('red-on');
        break;
      case '2':
        $('#2').addClass('blue-off').removeClass('blue-on');
        break;
      case '3':
        $('#3').addClass('yellow-off').removeClass('yellow-on');
        break;
      case '4':
        $('#4').addClass('green-off').removeClass('green-on');

    }

    if (correct) {
      setTimeout(function() {
        updateCounter(length);
        playSeq();
        correct = false;
      }, 500);
    }
    clearInterval(timeout);
    return false;
  });
  $('.push').mouseout(function() {
    var num = $(this).attr('id');
    switch (num) {
      case '1':
        $('#1').addClass('red-off').removeClass('red-on');
        break;
      case '2':
        $('#2').addClass('blue-off').removeClass('blue-on');
        break;
      case '3':
        $('#3').addClass('yellow-off').removeClass('yellow-on');
        break;
      case '4':
        $('#4').addClass('green-off').removeClass('green-on');
    }

    if (correct) {
      setTimeout(function() {
        updateCounter(length);
        playSeq();
        correct = false;
      }, 500);
    }
    clearInterval(timeout);
    return false;
  });

});
              
            
!
999px

Console