Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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="container">
  <div class="row">
    <div class="col-md-12">
      <h2 class="text-center">Simple Simon Game</h2>
    </div>
  </div>
  <div class="row">
    <div class="col-md-12">
      <div class="gamefield">
        <div class="btn-sett" data-toggle="modal" data-target="#myModal">
          <h5>Settings</h5>
</div>
        <div class="top-row">
          <div id="blue" class="gamebutton" onClick="addToPlayer(this.id)"></div>
        </div>
        <div class="middle-row">
          <div id="green" class="gamebutton" onClick="addToPlayer(this.id)"></div>
          <div id="gameNumber"><h2 id="clickNumber">0</h2></div>
          <div id="red" class="gamebutton" onClick="addToPlayer(this.id)"></div>
        </div>
        <div class="bottom-row">
          <div id="dark" class="gamebutton" onClick="addToPlayer(this.id)"></div>
        <div>
      </div>  
    </div>
  </div>
  <div class="row">
    <div class="col-md-12">

   

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h2 class="modal-title" id="myModalLabel">Settings!</h2>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-md-12 text-center">
          <h4 class="black">Strict mode?</h4>
          <p class="btn btn-primary text-center" id="strict" onClick="strict()"> Is currently Off</p>
          </div>
        </div>
        <div class="row">
          <div class="col-md-12 text-center">
          <h4 class="black">Reset?</h4>
          <p class="btn btn-warning text-center" data-dismiss="modal" onClick="newGame()"> Reset!</p>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" data-dismiss="modal">Save changes</button>
      </div>
    </div>
  </div>
</div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                @rich-black: #071013;
@kelly-green: #29BF12;
@tiffany-blue: #08BDBD;
@red: #F21B3F;
@dark: #FF9914;
@import 'https://fonts.googleapis.com/css?family=Muli';
body {
  background-color: @rich-black;
  color: white;
  font-family: 'Muli', sans-serif;
}

.gamefield {
  max-width: 480px;
  margin: 20px auto;
}

.align {
  display: flex;
  justify-content: center;
}

.top-row {
  .align;
}

.middle-row {
  display: flex;
  justify-content: space-around;
  align-items: center;
  margin: 15px auto;
}

.bottom-row {
  .align;
}

@buttonWidth: 90px;
.gamebutton {
  width: @buttonWidth;
  height: @buttonWidth;
  border-radius: 400px;
}

.border(@color) {
  border: 4px solid @color;
  margin: 20px;
  &:active {
    // Try deleting active  (better mobile performance)
    background-color: @color;
  }
}

.onhover(@color) {
  background-color: @color;
}

#blue {
  .border(@tiffany-blue);
}

#green {
  .border(@kelly-green);
}

#red {
  .border(@red);
}

#dark {
  .border(@dark);
}

#blue.hover {
  .onhover(@tiffany-blue);
}

#green.hover {
  .onhover(@kelly-green);
}

#red.hover {
  .onhover(@red);
}

#dark.hover {
  .onhover(@dark);
}

.btn-sett {
  font-size: 2.7em;
  text-align: left;
  transition: 500ms;
  width: 70px;
  margin-right: 340px;
  &:hover {
    color:  @kelly-green;
  }
}

.modal-title {
  .black;
}

.black {
  color: @rich-black;
  text-align: center;
}

#strict {
  margin: 5px auto;
  text-align: center;
}
              
            
!

JS

              
                var game = {
  count: 0,
  possibilities: ['#green','#blue', '#red', '#dark'],
  currentGame: [],
  player: [],
  sound:{
    blue: new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3'), 
    red: new Audio('https://s3.amazonaws.com/freecodecamp/simonSound2.mp3'), 
    dark: new Audio('https://s3.amazonaws.com/freecodecamp/simonSound3.mp3'), 
    green: new Audio('https://s3.amazonaws.com/freecodecamp/simonSound4.mp3')
  },
  strict: false,
}

function clearGame() {
  game.currentGame = [];
  game.count = 0;
  addCount();
}

function newGame() {
  clearGame();
}

function strict() {
  if (game.strict == false) {
    game.strict = true;
    $('#strict').html('Is currently On').removeClass('btn-primary').addClass('btn-danger');
  } else {
    game.strict = false;
    $('#strict').html('Is currently Off').removeClass('btn-danger').addClass('btn-primary');
  }
  
  newGame();
}

function showMoves() {
  var i = 0;
  var moves = setInterval(function(){
    playGame(game.currentGame[i]);
    i++;
    if (i >= game.currentGame.length) {
      clearInterval(moves);
    }
  }, 600)
  
  clearPlayer();
}

function sound(name) {
  switch(name) {
    case'#green':
      game.sound.green.play();
      break;
    case '#blue':
      game.sound.blue.play();
      break;
    case '#red':
      game.sound.red.play();
      break;
    case '#dark':
      game.sound.dark.play();
      break;
  };
}

function playGame(field) {
  $(field).addClass('hover');
  sound(field);
  setTimeout(function(){
      $(field).removeClass('hover');
  }, 300);
}

function clearPlayer() {
  game.player = [];
}

function addToPlayer(id) {
  var field = "#"+id
  console.log(field);
  game.player.push(field);
  playerTurn(field);
} 

function playerTurn(x) {
  if (game.player[game.player.length - 1] !== game.currentGame[game.player.length - 1]) {
    if(game.strict){
      alert('Try again! ...From scratch!');
      newGame();
    } else {
      alert('Wrong move! Try again!');
      showMoves();
    }
   } else {
      console.log('Good Move!');
      sound(x);
      var check = game.player.length === game.currentGame.length;
      if (check) {
        if(game.count == 20){
          alert('You won! Congrats.');
        } else {
          alert('Next round!');
          nextLevel();
        }
      }
    }
} 

function nextLevel() {
  addCount();
}

function generateMove(){
  game.currentGame.push(game.possibilities[(Math.floor(Math.random()*4))]);
  //alert(game.currentGame.length);
  showMoves();
}

function addCount() {
  game.count++;
  $('#clickNumber').addClass('animated fadeOutDown');
  
  setTimeout(function(){
    $('#clickNumber').removeClass('fadeOutDown').html(game.count).addClass('fadeInDown');
  }, 200);
  
  generateMove();
}

newGame();
              
            
!
999px

Console