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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 id="simon-game">
  <div id="back-circle"></div>
  <div id="simon-boxes">
    <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 591 585" style="enable-background:new 0 0 591 585;" xml:space="preserve">

      <path id="greenBox" class="color-box" d="M157,275c0,0,6.5-100,128.5-126V12c0,0-245.5,2.5-266.5,263C19,275,134,279,157,275z"/>

      <path id="redBox" class="color-box" d="M308.5,12c0,0,238.5,0,269.5,264.778H436.5c0,0-9-113.889-128-129.278V12z"/>

      <path id="blueBox" class="color-box" d="M308.5,428c0,0,115-16,127-128.5H578c0,0-15.5,251-269.5,268V428z"/>

      <path id="yellowBox" class="color-box" d="M156.5,299.5c0,0,21,113.5,129,129.5v138.5c0,0-245.5-11.5-266.5-268H156.5z"/>
    </svg>
  </div>
  
  <div id="center-circle">
    <h1>Simon</h1>
    <div id="count-screen"><p></p></div>
    <button id="start">START</button>
    <button id="strict">STRICT</button>
  </div>
    
</div>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Sigmar+One)
@import url(https://fonts.googleapis.com/css?family=Orbitron)

h1
  font-family: "Sigmar One"
  font-size: 2.75em
  transform: translateX(31px)      

#simon-game
  position: relative
  width: 550px
  height: 550px
  margin: 0 auto
  
#back-circle
  height: 550px
  width: 550px
  background-color: #181818
  border-radius: 50%
  position: absolute
  margin: 0 auto

#simon-boxes
  width: 550px
  height: 550px
  position: absolute
  margin: 6px -1px
  #greenBox
    fill: #00A74A /* onClick: #4AD95D */
    cursor: pointer
    cursor: hand
  #redBox
    fill: #F82A15
    cursor: pointer
    cursor: hand
  #yellowBox
    fill: #FEF735
    cursor: pointer
    cursor: hand
  #blueBox
    fill: #0297EB
    cursor: pointer
    cursor: hand
#center-circle
  height: 225px
  width: 225px
  background-color: #fff
  border-radius: 50%
  position: absolute
  margin: 29.5% 30%
  -webkit-user-select: none 
  -moz-user-select: none     
  -ms-user-select: none   
  user-select: none  
  
#count-screen
  height: 40px
  width: 65px
  background-color: black
  border-radius: 15%
  transform: translate(84px, -25px)
  p
    transform: translate(6px, 6px)
    color: red
    font-family: "Orbitron"
    font-size: 2em
  
#start
  height: 30px
  width: 55px
  border-radius: 15%
  cursor: pointer
  cursor: hand
  outline: none
  transform: translate(55px, -10px)
  
#strict
  height: 30px
  width: 55px
  border-radius: 15%
  cursor: pointer
  cursor: hand
  outline: none
  transform: translate(60px, -10px)
  
#highlight
  opacity: .2
  
.red-button
  background-color: red
              
            
!

JS

              
                $(document).ready(function(){ 
  var playerClick = 0;
  var strict = false;
  var noButtons = true;
  var sequence = [];
  var boxes = ["greenBox", "redBox", "blueBox", "yellowBox"];
  
  // *Start the Game
  
  function simonAdd() { // add a value to sequence
    var x = Math.floor(Math.random() * 4);
    sequence.push(boxes[x]);
    console.log(sequence);
  }
  
  function simonSays() { // demonstrate sequence for player
    noButtons = true;
    var delay;
    if (sequence.length > 15) {
      delay = 400;
    } else if (sequence.length > 10) {
      delay = 500;
    } else if (sequence.length > 5) {
      delay = 600;
    } else {
      delay = 700;
    }
    var wait = setTimeout(function() { // slight pause between end of player input and beginning of playback
      for (var i = 0; i < sequence.length; i++) {
        var says = setTimeout(function(par) {
          sounds[par].play();
          $("#" + par).effect("bounce", 1);
        }, delay * (i + 1), sequence[i]);
      }
    }, 800);
    var noClickies = setTimeout(function() {
      noButtons = false;
    }, delay * sequence.length);
  }
  
  function setCount() { // set the counter at the center of the game
    if (sequence.length < 10) {
      $('#count-screen p').text("0" + (sequence.length).toString());
    } else {
      $('#count-screen p').text((sequence.length).toString());
    }
  };
  
  function simonStart() { // first move
    sequence = [];
    playerClick = 0;
    simonAdd(); 
    simonSays();
    setCount();
  }
  
  // * Sound Effects *
  var sounds = {
    greenBox: new Audio("https://s3.amazonaws.com/freecodecamp/simonSound1.mp3"),
    redBox: new Audio("https://s3.amazonaws.com/freecodecamp/simonSound2.mp3"),
    blueBox: new Audio("https://s3.amazonaws.com/freecodecamp/simonSound3.mp3"),
    yellowBox: new Audio ("https://s3.amazonaws.com/freecodecamp/simonSound4.mp3"),
  };
  
  function playSound(that) {
    var thisSound = that.id;
    sounds[thisSound].currentTime=0;
    sounds[thisSound].play();
  };
  
  function highlightBox(that) {
    $("#" + that.id).effect("bounce", 1);
  };
  
  function checkMove(that) { // check player button press against sequence array
    var thatID = that.id;
    return thatID === sequence[playerClick];
  };
  
  function winningSequence() { // what happens when you get to 20
    $('#count-screen p').text("<!!!>");
    var times = 0;
    var theBlinkies = setInterval(function() {
      times += 1;
      var blinkTop = setTimeout(function() {
        $('#greenBox').effect('bounce', 1);
        $('#redBox').effect('bounce', 1);
      }, 250);
      var blinkBottom = setTimeout(function() {
        $('#yellowBox').effect('bounce', 1);
        $('#blueBox').effect('bounce', 1);
      }, 1000);
      if (times > 7) {
        clearInterval(theBlinkies);
        var newGame = setTimeout(function() { 
          simonStart();
        }, 1500);
      }
    }, 250);
    playerClick = 0;
    sequence = [];
  }
  
  // * Click Events *
  $('.color-box').on('click', function() { // when the player clicks a color button
    if (noButtons) {
      return;
    }
    playSound(this);
    highlightBox(this);
    if (!checkMove(this)) { // if player presses wrong button:
      if (strict) {
        noButtons = true;
        $('#count-screen p').text("??");
        var startAgain = setTimeout(function() {
          simonStart();
          noButtons = false;
        }, 1500);
      } else {
        $('#count-screen p').text("??");
        playerClick = 0;
        var startAgain = setTimeout(function() {
          simonSays();
          setCount();
        }, 1500);
        console.log('got it wrong, bro');
      }
    } else { // if player presses correct button:
       if (playerClick === sequence.length - 1) { // if sequence is complete:
        setCount();
        simonAdd();
        simonSays(); 
        playerClick = 0;
        if (sequence.length > 19) {
          winningSequence();
        }
      } else { // if there are more buttons to press:
        playerClick++;
      }
    } 
  });
  
  $('#start').on('click', function() { // when the player clicks start
    noButtons = false;
    simonStart();    
  });
  
  $('#strict').on('click', function (){ // when the player clicks strict
    if (strict) {
      strict = false;
      $(this).removeClass('red-button');
    } else {
      strict = true;
      $(this).addClass('red-button');
    }
  });
  
});
              
            
!
999px

Console