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="container" id="guess">
    <svg viewBox="0 0 1024 1024" xml:space="preserve">
      <circle class="outline" cx = "512" cy="512" r = "502"></circle>
      <path class = "yellow butt" id="guess-4" onClick="tester(4)"
      d="M529.822,985.95c57.674-2.121,202.928-24.167,317.26-138.499
      	c111.002-111.002,136.222-258.879,138.459-316.168H747.165c-9.584,59.998-33.085,116.365-78.917,155.332
         c-38.025,32.328-89.863,56.617-138.426,61.005V985.95z"></path>
      <path class = "blue butt" id="guess-3" onClick="tester(3)"
      d="M39.346,531.282c2.121,57.674,24.166,202.929,138.498,317.261
      	c111.002,111.001,258.88,136.221,316.168,138.458V748.625c-59.998-9.584-116.365-33.086-155.331-78.917
      	c-32.329-38.025-56.618-89.863-61.005-138.426H39.346z"></path>
      <path class = "red butt"  id="guess-2" onClick="tester(2)" d="M985.064,493.525c0,0-11.781-191.99-138.498-317.26C715.272,46.47,530.398,37.806,530.398,37.806v238.376
      	c0,0,80.602,4.818,144.4,65.851c64.395,61.603,71.936,151.492,71.936,151.492H985.064z"></path>
      <path class = "green butt"  id="guess-1"  onClick="tester(1)" d="M495.064,38.858c-57.673,2.121-202.928,24.167-317.26,138.499C66.803,288.358,41.583,436.236,39.346,493.524
      	h238.376c9.584-59.998,33.085-116.365,78.917-155.331c38.025-32.329,89.863-56.618,138.425-61.005V38.858z"></path>
      <text class = "simon" x="320" y="450">SIMON.</text>
      <circle id="onOff" class="off" onClick="turnOn()" cx = "636" cy = "527" r = "50"></circle>
      <rect class="menu" ry = "10" rx = "10" x = "396" y = "614"></rect>
      <circle id="strictLight" cx = "581" cy = "599" r = "7"></circle>
      <circle id="strictMode" cx = "581" cy = "645" r = "21" onClick="strictMode()"></circle>
      <circle id="levels" cx = "511" cy = "645" r="21" onClick="increaseMax()"></circle>
      <circle id="newGame" cx = "441" cy = "645" r="21" onClick="newGame()"></circle>
    <text class="smbuttons" fill="#fff" x="424" y="691">new</text>
    <text class="smbuttons" fill="#fff" x="492" y="691">level</text>
    <text class="smbuttons" fill="#fff" x="561" y="691">strict</text>
      <rect class="counter" x = "323" y = "478" rx = "10" ry = "10"></rect>
      <text  x="335" y="550" class="static-text">88888888</text>
      <text  x="335" y="550" class="running-text"></text>
      <g>
	<path class = "onSym off"  d="M644.376,517.402c9.917,8.006,5.525,23.631-7.542,24.187c-13.173,0.561-17.305-16.915-7.543-24.149
		c2.56-1.897,0.07-6.241-2.523-4.318c-13.905,10.307-8.382,31.217,8.708,33.41c7.521,0.965,14.672-4.02,17.899-10.504
		c3.83-7.694,0.997-16.945-5.464-22.16C645.428,511.862,641.866,515.377,644.376,517.402L644.376,517.402z"></path>
</g>
<g>
	<path class = "onSym off"   d="M634,503.75c0,9.167,0,18.333,0,27.5c0,3.225,5,3.225,5,0c0-9.167,0-18.333,0-27.5
		C639,500.526,634,500.526,634,503.75L634,503.75z"></path>
</g>
    </svg>
  </div>
<div class="dissed" style="z-index:-1"></div>
            
          
!
            
              .container {
  max-width: 600px;
  margin:0 auto;
}

.running-text {
  font-family: 'Conv_Calculator', Fallback, Sans-Serif;
  font-size: 3em;
  fill: red;
  letter-spacing: 1px;
}

.static-text {
  font-family: 'Conv_Calculator', Fallback, Sans-Serif;
  font-size: 3em;
  fill: #240f0f;
}

.onSym.off {
  fill: #fff;
}

.onSym.on {
  fill: #333;
}
.simon {
  font-family: 'Archivo Black', Fallback, Sans-Serif;
  font-size: 6em;
  fill: #fff;
}

.smbuttons {
  font-family: 'Arial', Fallback, Sans-Serif;
  font-size: 1.2em;
  fill: #fff;
}

.butt {
cursor:pointer;
}

.outline {
  fill-rule: evenodd;
  fill: #130D1B;
}

.green {
  fill: #005e00;
}
.green:active,.green:focus, .green.flash {
  fill: #00ff00;
  transition: all .2s;
}

.red {
  fill: #9e0202;
}

.red:active,.red:focus, .red.flash {
  fill: #ff0000;
  transition: all .2s;
}
.blue {
  fill: #01017b;
}
.blue:active,.blue:focus, .blue.flash {
  fill: #3535ff;
  transition: all .2s;
}
.yellow {
  fill: #a8a800;
}

.yellow:active,.yellow:focus, .yellow.flash {
  fill: #ffff00;
  transition: all .2s;
}

#onOff {
  cursor:pointer;
}

.off {
  fill: #780707;
}

.on {
  fill: #ffc65d;
}

.counter {
  height:100px;
  width: 245px;
  fill: #110707;
}

.menu {
  height: 60px;
  width: 232px;
  fill: #110707;
}

.dissed {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background-color: rgba(0,0,0,0);
}

#strictMode {
  fill: #ff0000;
}

#strictLight {
  fill: black;
}

#levels {
  fill: #ffff00;
}

#newGame {
  fill: #66fd66;
}
            
          
!
            
              

var seq = [];
var corr = [];
var guesses = [];
var maxNumbers = 5;
var strictGame = false;
turnOn();
//create audio element
var x = document.createElement("AUDIO");

//sound played according to flash
var playSound = function (num) {
  var e = [
    '',
    'https://s3.amazonaws.com/freecodecamp/simonSound1.mp3',
    'https://s3.amazonaws.com/freecodecamp/simonSound2.mp3',
    'https://s3.amazonaws.com/freecodecamp/simonSound3.mp3',
    'https://s3.amazonaws.com/freecodecamp/simonSound4.mp3'
  ];
  
  if (x.canPlayType("audio/mpeg")) {
    x.setAttribute("src",e[num]);
    x.onloadeddata  = function() {
      x.play();
    // alert("Starting to load audio");
};
    
  }    
}  

//onoff
function turnOn () {
  $( "#onOff" ).toggleClass('on off');
  $( ".onSym" ).toggleClass('on');
  var text = "READY TO PLAY SIMON?  ";
  sequencer([1,3,4,2]);
  ($('#onOff').is('.on')) ? runner(text) : off()
}

//if off, reset all values
function off () {
  //timeout declared in window way down below, the timeouts are cleared here.
  //too many timeouts...
  var d = window.ttime;
  for (var j=(d-d);j<(d+1);j++) {
    window.clearTimeout(j);
  }
  $('.running-text').html('')
  strictGame = false
  $('#strictLight').css('fill','black')
  maxNumbers = 5;
  reset();

}
//simple reset, can also be used as a reset button in-game
function reset () {
  ($('#onOff').is('.off')) ? null :
  (
    guesses=[],
    seq=[],
    corr = [],
    testRunner(false)
  )
}

//increase levels
function increaseMax () {
    ($('#onOff').is('.off')) ? off() :
    (  maxNumbers+=5,
      setTimeout(function() {
        runner('WIN AT '+maxNumbers+' GOES');
      },100)
    )
}

//set strict mode
function strictMode () {
  ($('#onOff').is('.off')) ? off() :
    (
      strictGame=!strictGame,
      (strictGame)
      ? (
      runner('STRICT MODE: ACTIVE '),
      $('#strictLight').css('fill','red')
      )
      : (
        $('#strictLight').css('fill','black'),
        runner('EASY MODE: ACTIVE ')
      )
    )
}

//starting a new game
function newGame () {
  ($('#onOff').is('.off')) ? off() : (  reset(),
    setTimeout(function() {
      start();
    },200)
  )
}

//gah!! timeout within timeout!
function start () {
  runner("NEW GAME("+maxNumbers+")")
  setTimeout(function() {
      runner('  WATCH ');
    setTimeout(function() {
      runner('  START ');
    },1500);
    numbers();
  },2500);
}

//generate a number, send it to the sequencer
function numbers () {
  seq.push(generateNum());
  sequencer();
}

//random number between 1 and 4
function generateNum () {
  var min = Math.ceil(1);
  var max = Math.floor(4);
  return Math.floor(Math.random() * (max - min+1)) + min;
}

//run the sequencer that runs the flashes
function sequencer (data) {
  if(data) {
    seq=data;
  }
  var count=0;
  // nested timeouts..   :/
  for (var i = 0; i < seq.length; i++) {
    setTimeout(function() {
      var num = seq[i];
      var guess = document.getElementById('guess-'+num);
      return ()=> {
        count++;
        (count===seq.length) ? testRunner(false) : testRunner(true)
        playSound(num);
        guess.classList.add('flash');
        setTimeout(function (){
          guess.classList.remove('flash');
        },900)
      };
    }(i), 1100*i);
  }
}
//game win sequence
function wonGame () {
  runner("YOU WON!   PRESS YELLOW TO PLAY FOR "+(maxNumbers+5)+"  ");
  sequencer([1,3,4,2]);
  setTimeout(function () {
    reset();
  },3710)
}

//disables the buttons whilst something is going on with an invisible div placed on top.
function testRunner (data) {
  (data) ? $('.dissed').css('z-index',1) : $('.dissed').css('z-index',-1)
  setTimeout(function () {
    (data) ? $('.dissed').css('z-index',1) : $('.dissed').css('z-index',-1)
  },800)
}


//text runner
function runner (data) {
  //doesn't work in ie so uses polyfill above to remove excess characters
  $('.running-text').html(' ')
  var count=0;
  var text = data;
  for (var i = 0; i < text.length; i++) {
    //add a timeout function to document window so it can be accessed later
    window.ttime = setTimeout(function() {
      var num = text[i];
      return function () {
        count++;
        (count===text.length) ? testRunner(false) : testRunner(true);
        //max number of characters specified here
        ($('.running-text')[0].childNodes.length>7) 
          ? ($('.running-text')[0].childNodes[0].remove(0), $('.running-text').append(num))
        : $('.running-text').append(num);
          
        
      }
    }(i), 150*i);
  }

}
//tester to make sure button presses only do something when the unit is on. 
function tester (data) {
  ($('#onOff').is('.on')) ? test(data) : null;
}
//test user inputs and provide feedback on sequence completion
function test (data) {
  playSound(data);
  guesses.push(data);
  var comments = {
    one:" OK.TRY ",
    three:" NEXT :",
    five:" KEEP IT UP : ",
    seven:" EXCELLENT GO FOR ",
    more:" AWESOME! TRY "
  }
  if (guesses[guesses.length-1]===seq[guesses.length-1] && seq[0]!==undefined) {
    corr.push(data);
    if (corr.length===seq.length) {
      var sq = seq.length;
      (sq===maxNumbers) ? wonGame() :
      (sq<3) ? runner(comments.one+(sq+1)) :
      (sq<5) ? runner(comments.three+(sq+1)) :
      (sq<7) ? runner(comments.five+(sq+1)) :
      (sq<9) ? runner(comments.seven+(sq+1)) :
      runner(comments.more+(sq+1));
      
      (sq<maxNumbers)
      ?(
        guesses=[],
        corr=[],
        setTimeout(function() {
          numbers();
        },2000)
      )
      : null;
}
  } else if(seq[0]!==undefined && strictGame==false) {
    runner("WRONG.....TRY AGAIN");
    guesses=[];
    corr = [];
    setTimeout(function() {
      sequencer();
    },3500)
  } else if(seq[0]!==undefined && strictGame==true) {

    runner('WRONG.. YOU LOST')
    setTimeout(function() {
      reset();
    },1000)
  }
}

//polyfill for the runner in ie
(function (arr) {
  arr.forEach(function (item) {
    if (item.hasOwnProperty('remove')) {
      return;
    }
    Object.defineProperty(item, 'remove', {
      configurable: true,
      enumerable: true,
      writable: true,
      value: function remove() {
        this.parentNode.removeChild(this);
      }
    });
  });
})([Element.prototype, CharacterData.prototype, DocumentType.prototype]);

            
          
!
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.

Console