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.

            
                <audio>
    <p>Your browser does not support the <code>audio</code> element.</p>
  </audio>

<div class="simon">
  <div class="buttons">
    <div class="button top left "></div>
    <div class="button top right"></div>
    <div class="button bottom left"></div>
    <div class="button bottom right"></div>
  </div>
  <div class="controls">
    <div class="name">Simon</div>

    <div class="counter"><span>- -</span></div>
  
    <div class="button-row">
      <div class="group start-group">
        <div class="start">Start</div>
        <span class="light start-light"></span>
      </div>
        
      <div class="group reset-group">
        <div class="reset">Reset</div>
        <span class="light reset-light"></span>
      </div>
      <div class="group strict-group">
        <div class="strict">Strict</div>
        <span class="light strict-light on"></span>
      </div>
    </div>

  </div>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Lato:400,300,700);

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: lato, san-serif;
}

.simon {
  position: relative;
  height: 500px;
  width: 500px;
  background-color: #333;
  border-radius: 50%;
  margin: 5% auto;
}

.top, .bottom, .right, .left {
  position: absolute;
  width: 45%;
  height: 45%; 
}

.top {
  top: 5%;
  border-bottom: #333 solid 10px;
}

.bottom {
  top: 50%;
    border-top: #333 solid 10px;
}

.right {
  left: 50%;
  border-left: solid #333 10px;
}

.left {
  left: 5%;
  border-right: solid #333 10px;
}

.top.left {
  background-color: green;
  border-radius: 100% 5% 5% 5%;
  
}

.top.right {
  background-color: red;
  border-radius:5%  100% 5% 5%;
  
}


.bottom.left {
  background-color: yellow;
  border-radius:  5%  5% 5% 100% ;
  
}

.bottom.right {
  background-color: blue;
  border-radius:  5% 5% 100% 5% ;
  
}

.controls {
  position: relative;
  background-color: white;
  height: 40%;
  width: 40%;
  border-radius: 50%;
  top: 30%;
  left: 30%;
  border: solid #333 15px; 
}

.name {
  text-align: center;
  margin: 10% 0;
  font-size: 2em;
}

.counter {
  position: absolute;
  margin: auto;
  background-color: #333;
  color: #49fb35;
  text-align: center; 
  height: 20%;
  width: 40%;
  left: 0;
  top: 0px;
  right: 0;
  bottom: 20px;
  border-radius: 5px;
}

.counter>span {
  margin: 15px 0 0 0;
  display: inline-block;
}


.button-row {
  position: absolute;
  max-width: 150px;
  margin: 0 auto;
  //clear: both;
  left: 0;
  top: 0px;
  right: 0;
  bottom: 0px;
  top: 55%;
  left: 10%;
}

.light {
  float: left;
  padding: 0 4%;
}

.group {
  width: 30%;
  float: left;
  font-size: .8em;
  text-align: center;
}



.light {
  width: 18px;
  height: 18px;
  background-color: red;
  margin: 10px;
  border-radius: 50%;
  box-shadow: 3px 3px 3px #333333;
}

.on {
  background-color: green;
}

.btn-pressed {
  opacity: 0.3;
  filter: alpha(opacity=30); /* For IE8 and earlier */
  
}

.pressed {
  box-shadow: 1px 1px 1px #aaaaaa;
  box-shadow: -1px -1px 1px #aaaaaa;

  
}
            
          
!
            
              $(document).ready(function() {
  console.log("ready!");
/*
  var sounds = [
    new Audio('http://www.orangefreesounds.com/wp-content/uploads/2015/11/Meowing-sound.mp3?_=1'),
    new Audio('http://www.orangefreesounds.com/wp-content/uploads/2015/09/Cat-meow-nervous.mp3?_=1'),
    new Audio('http://www.orangefreesounds.com/wp-content/uploads/2015/06/Cat-meow-sound-3.mp3?_=1'),
    new Audio('http://www.orangefreesounds.com/wp-content/uploads/2015/04/Cat-hissing-sound-2.mp3?_=1')
  ];

  var sounds = [
    new Audio('http://www.soundjig.com/mp3/soundfx/voices/whatsgoodboy.mp3'),
    new Audio('http://www.soundjig.com/mp3/soundfx/voices/high_pitched_hello.mp3'),
    new Audio('http://www.soundjig.com/mp3/soundfx/human/yeaahh.mp3'),
    new Audio('http://www.soundjig.com/mp3/soundfx/human/hello.mp3')
  ];
*/
  var sounds = [
    new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3'), 
    new Audio('https://s3.amazonaws.com/freecodecamp/simonSound2.mp3'), 
    new Audio('https://s3.amazonaws.com/freecodecamp/simonSound3.mp3'), 
    new Audio('https://s3.amazonaws.com/freecodecamp/simonSound4.mp3')
  ]
  
  var soundFile;
  var lightSequence = [];
  var gameActive = false;
  var currentStep = 5;
  var button = jQuery('.button').eq(lightSequence[0]);

  $('.start-light').click(function() {
    if (!gameActive) {
      gameActive = true;

      //Create Randmon Sequence
      generateLightSequence(lightSequence)

      function generateLightSequence(arr) {
        for (var i = 0; i < 20; i++) {
          var sequence = Math.floor(Math.random() * 4)
          arr.push(sequence);
        }
        console.log(arr)
      }

      playSequence(loopThrough, button, currentStep);

      function playSequence(loopThrough, button, step) {
         button = jQuery('.button').eq(lightSequence[step]);
         button.toggleClass("pressed");
         timerID = setTimeout(function(){
           button.toggleClass("pressed");
         },1000);
         step -= 1;
        
        if (step >0 ){
          intervalID = setInterval(function() {
            loopThrough(step, button);
            step -= 1;
            if (step < 0) clearInterval(intervalID);
          }, 1000)
        }
      }

      function loopThrough(step, button) {
        console.log("now playing step: " + step + ", sound: " + lightSequence[step]);
        updateCounter(step);
        button = jQuery('.button').eq(lightSequence[step]);
        //button.toggleClass("pressed");
        sounds[lightSequence[step]].play();
        //button.toggleClass("pressed");
        soundID = setTimeout(function() {
         // button.toggleClass("pressed");
        }, 500);
      }

      //Wait for player input

      // if player sequence matches current sequence
      //   if step = 20 game winner (exit game loop)! 

      // -> go to next sound
      // else 
      // -> if total misses < 1;
      //    misses +=1
      //    play alarm sound 
      //    replay current sequence
      //    (wait for player input (recall this function recursively?))

    } else {
      gameActive = false;
      //resent any timers
    }
  })

  $('.light').click(function() {
    $(this).toggleClass("on");
  });

  $('.light').mousedown(function() {
    $(this).toggleClass("pressed");
  })

  $('.light').mouseup(function() {
    $(this).toggleClass("pressed");
  })

  $('.button').mousedown(function() {
    $(this).toggleClass("btn-pressed");
    console.log($('.button').index(this));
    playSoundUser(sounds[$('.button').index(this)]);
  })

  $('.button').mouseup(function() {
    $(this).toggleClass("btn-pressed");
  })

  
  function updateCounter(step){
    $('.counter').text(step);
  }; 
  function playSoundUser(soundFile) {
    soundFile.play();
  };
});
            
          
!
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