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 id="outer-wrapper">
  <div id="wrapper">
    <div class="sqr" id="one"></div>
    <div class="sqr" id="two"></div>
    <div class="sqr" id="three"></div>
    <div class="sqr" id="four"></div>
    <div id="inner-wrapper">
      <div id="top-half">
        <div id="screen"></div>
      </div>
      <div id='bottom-half'>
        <div class ='btn power' title='on/off'></div>
        <div class ='btn start' title='start'></div>
        <div class ='btn strict' title='strict mode'></div>
        </div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                
@import url('https://fonts.googleapis.com/css?family=VT323');

.sqr{
  width: 200px;
  height: 200px;
  margin:10px;
  display: inline-block;
}



#wrapper{
  position:relative;
  width:446px;
  background:#333;
  border-radius:100%;
  padding:20px;
  margin:0 auto;
}

#inner-wrapper{
  position:absolute;
  width:220px;
  height:220px;
  background:#ecf0f1;
  border:20px solid #333;
  border-radius:100%;
  top:24%;
  left:23%;
  overflow:hidden;
}

html, body{
  background:#e74c3c;
}

#one{
  border-top-left-radius:100%;
  background:#27ae60;
}

#two{
  border-top-right-radius:100%;
  background:#c0392b;
}

#three{
  border-bottom-left-radius:100%;
  background:#f39c12;
}

#four{
  border-bottom-right-radius:100%;
  background:#2980b9;
}

#top-half{
  background:rgba(0,0,0,0.4);
  width:100%;
  height:100px;
  position:relative;
  text-align: center;
}

#screen{
  background:rgba(150, 40, 27, 0.4);
  width:70px;
  height:60px;
  margin:0 auto;
  position:absolute;
  left:75px;
  top:20px;
  border-radius:10%;
  font-size:50px;
  color:rgba(150, 0, 0, 0.3);
  font-family: 'VT323', monospace;
}

.btn{
  width:30px;
  height:30px;
  border-radius:100%;
  display:inline-block;
  margin:10px;
}

#bottom-half{
  position:relative;
  width:100%;
  height:100px;
  text-align:center;
  font-size: 14px;
  padding-top:15px;
}

.power{
  background:red;
}

.start{
  background:#2ecc71;
}

.strict{
  background:#1abc9c;
}

#one.light, #one:active{
  background: #2ecc71;
  box-shadow: 0px 0px 2px 2px rgba(46, 204, 113,1.0);
}

#two.light, #two:active{
  background: #e74c3c;
  box-shadow: 0px 0px 2px 2px rgba(231, 76, 60,1.0);

}

#three.light, #three:active{
  background: #f1c40f;
  box-shadow: 0px 0px 2px 2px rgba(241, 196, 15,1.0);
}

#four.light, #four:active{
  background: #3498db;
  box-shadow: 0px 0px 2px 2px rgba(52, 152, 219,1.0);
}
              
            
!

JS

              
                
var sqrArray =['one', 'two', 'three', 'four']; 

var sound_1 = 'https://s3.amazonaws.com/freecodecamp/simonSound1.mp3';
var sound_2 = 'https://s3.amazonaws.com/freecodecamp/simonSound2.mp3';
var sound_3 = 'https://s3.amazonaws.com/freecodecamp/simonSound3.mp3';
var sound_4 = 'https://s3.amazonaws.com/freecodecamp/simonSound4.mp3';

var game = {
        has_power: false,
        count: 0,
        sequence: [],
        is_strict: false,
        reset: function() {
          this.count = 0;
          this.sequence = [];
        }
}

// get random array element
function random_sqr() {
  return sqrArray[Math.floor(Math.random() * 4)];
} 

// adds and remove green background
function makelight(n) {
  $('#' + n).addClass('light');
  playSound(n);
  setTimeout(function() {
    $('#' + n).removeClass('light');
  }, 1000);
}

// assignes makelight() in order of array elements
function play_ev() {
  $('#screen').html(game.count);
  var i = 0;
  var sequenceInter = setInterval(function() {
    makelight(game.sequence[i]);
    i++;
    if(i>=game.sequence.length) {
      clearInterval(sequenceInter);
      $('.sqr').css('pointer-events', 'auto');
    }
    
  }, 2000);
}

// adds random sqr to game
function addToSequence() {
  game.sequence.push(random_sqr());
}

function play_game() {
  game.count++;
  
  game.sequence.push(random_sqr());
  play_ev();
}
var checkCount = 0;
//player picks sqr
function player_pick() {
  $('.sqr').css('pointer-events', 'none');
  console.log('no clicking!');
  checkCount = 0;
  play_game();
 // player_turn();
}


// Checks player choice
//function check_move() {
  $('.sqr').click(function() {
    playSound(this.id);
    if(this.id === game.sequence[checkCount]) {
      console.log('Correct!');
      checkCount++;
      if(checkCount === game.sequence.length) {
        if(checkCount === 20) {
          console.log('game over');
          $('#screen').html('**');
          setTimeout(function(){
            game.reset();
            player_pick();
          })
        }  else {
        console.log('end of round');
        player_pick();
        }
      }
     // player_turn();
    } else if(this.id !== game.sequence[checkCount]) {
      console.log('incorrect');
      $('.sqr').css('pointer-events', 'none');
      console.log('no clicking!');
      $('#screen').html('!!');
      checkCount = 0;
      setTimeout(function(){
        if(game.is_strict) {
        game.reset();
        player_pick();
      } else {
        play_ev();
      }
      }, 2000)
    }
  })

$('.power').click(function() {
  if(!game.has_power) {
    $('#screen').html('--');
    game.has_power = true;
    
  } else {
    $('#screen').html('');
    game.has_power = false;
    game.reset();
   
  }
})

$('.strict').click(function() {
   if(game.is_strict) {
    game.is_strict = false;
    $('.btn.strict').css({'border':'', 'width':'30px', 'height':'30px'});
  } else {
    game.is_strict = true;
    //$('.btn.strict').css('border','3px solid rgba(41, 128, 185,0.5)');
    $('.btn.strict').css({'border':'3px solid rgba(41, 128, 185, .2)', 'width':'24px', 'height':'24px'});
  }
})

 $('.start').click(function(){
        if(game.has_power) {
        player_pick();
        }
    })

 function playSound(tile) {
        console.log('sound');
        var snd;
        switch(tile) {
          case 'one':
            snd = new Audio(sound_1);
          break;
          case 'two':
            snd = new Audio(sound_2);
            break;
          case 'three':
            snd = new Audio(sound_3);
          break;
          case 'four':
            snd = new Audio(sound_4);
          break;
        }
        snd.play();
    }
              
            
!
999px

Console