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="wrapper" ng-app="simonApp">
  <div class="game" ng-controller="simonCtrl">
    <a href class="button red" id="red" ng-click="click('#red')"></a>
    <a href class="button green" id="green" ng-click="click('#green')"></a>
    <a href class="button blue" id="blue" ng-click="click('#blue')"></a>
    <a href class="button yellow" id="yellow" ng-click="click('#yellow')"></a>
    
    <div class="control-panel">
      <p id="turn">{{ turn }}</p>
      <div>
        <a href class="start-btn clickable" ng-click="startGame()">Start</a>
        <input type="checkbox" id="strict">
        <label class="strict-mode" for="strict" ng-click="setStrict()"><span>Strict</span></label>
      </div>
    </div>
  </div>
  <p>Made by <a href="https://saintgeo23.github.io/">saintgeo23</a> for <a href="https://www.freecodecamp.com/">FreeCodeCamp</a> project</p>
</div>
<div id="wave"></div>
              
            
!

CSS

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

* {
  margin: 0;
  padding: 0;
  list-style: none;
  text-decoration: none;
  font-family: 'VT323', sans-serif;
}

.wrapper {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center; 
  overflow: auto;
}

.game {
  position: relative;
  width: 600px;
  height: 600px;
  -moz-column-count: 2;
  -webkit-column-count: 2;
  column-count: 2;
  column-gap: 0;
  -moz-column-gap: 0;
  -webkit-column-gap: 0;
  box-sizing: border-box;
  border-radius: 10px;
}

.button {
  display: inline-block;
  float: left;
  width: 100%;
  height: 300px;
}

.button.red {
  background-color: #f44336;
  border-radius: 10px 0 0 0;
}

.button.blue {
  background-color: #03A9F4;
  border-radius: 0 10px 0 0;
}

.button.yellow {
  background-color: #FDD835;
  border-radius: 0 0 10px 0;
}

.button.green {
  background-color: #4CAF50;
  border-radius: 0 0 0 10px;
}

.button.red.clickable:active,
.button.red.active {
  background-color: #ef9a9a;
}

.button.green.clickable:active,
.button.green.active {
  background-color: #A5D6A7;
}

.button.blue.clickable:active,
.button.blue.active {
  background-color: #90CAF9;
}

.button.yellow.clickable:active,
.button.yellow.active {
  background-color: #FFF59D;
}

.control-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -100px 0 0 -100px;
  z-index: 999;
  width: 200px;
  height: 200px;
  text-align: center;
  box-shadow: 0 5px 25px -5px #212121;
  border-radius: 10px;
  background-color: #212121;
  overflow: hidden;
}

.control-panel p {
  display: block;
  width: 200px;
  height: 100px;
  line-height: 100px;
  vertical-align: middle;
  font-size: 6em;
  color: #FF5722;
  background-color: #212121;
}

.control-panel div {
  width: 200px;
  height: 100px;
  -moz-column-count: 2;
  -webkit-column-count: 2;
  column-count: 2;
  column-gap: 0;
  -moz-column-gap: 0;
  -webkit-column-gap: 0;
}

.control-panel .start-btn {
  position: absolute;
  bottom: 0;
  left: 0;
  display: block;
  width: 100px;
  height: 100px;
  line-height: 100px;
  vertical-align: middle;
  text-align: center;
  background-color: #212121;
  color: #ffffff;
  font-size: 2em;
}

.control-panel .start-btn:hover {
  background-color: #616161;
}

.control-panel .start-btn:active {
  background-color: #ffffff;
  color: #f44336;
}

.control-panel #strict {
  display: none;
}

.control-panel .strict-mode {
  position: absolute;
  bottom: 0;
  right: 0;
  z-index: 9999;
  display: block;
  width: 100px;
  height: 100px;
  line-height: 100px;
  vertical-align: middle;
  text-align: center;
  background-color: none;
  cursor: pointer;
}

.control-panel #strict + label span {
  position: absolute;
  bottom: 0;
  right: 0;
  display: block;
  width: 100px;
  height: 100px;
  line-height: 100px;
  vertical-align: middle;
  text-align: center;
  background-color: #212121;
  color: #ffffff;
  font-size: 2em;
}

.control-panel #strict:checked + label span {
  background-color: #ffffff;
  color: #f44336;
}

.wrapper p {
  text-align: center;
}

.wrapper > p {
  margin-top: 10px;
  color: #212121;
}

.wrapper p a {
  color: #FF5722;
}


@media screen and (max-width: 600px) {
  .game {
    width: 300px;
    height: 300px;
  }
  .button {
    height: 150px;
  }
  .control-panel {
    margin: -50px 0 0 -50px;
    width: 100px;
    height: 100px;
    border-radius: 7px;
  }
  .control-panel p {
    width: 100px;
    height: 50px;
    line-height: 50px;
    font-size: 3em;
  }
  .control-panel .start-btn,
  .control-panel .strict-mode {
    width: 50px;
    height: 50px;
    line-height: 50px;
    font-size: 1em;
  }
  .control-panel #strict + label span {
    width: 50px;
    height: 50px;
    line-height: 50px;
    font-size: 1em;
  }
  .wrapper > p {
    font-size: 0.7em;
  }
}
              
            
!

JS

              
                /* You can change game length. Just set $scope.gameLength variable. Hint: also you can see full sequence in console */

var app = angular.module('simonApp', []);

app.controller('simonCtrl', ['$scope', '$timeout', function($scope, $timeout) {

  // Game length
  $scope.gameLength = 20;
  
  // Playing with HTML5 Audio API
  var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
  
  var oscillator = audioCtx.createOscillator();
  var gainNode = audioCtx.createGain();
  // Notes C, D, E, F
  var freqs = {
    '#red': 261.63, 
    '#blue': 293.33, 
    '#yellow': 329.63, 
    '#green': 349.23
  };
  
  oscillator.type = 'sine';
  oscillator.frequency.value = 261.63;
  oscillator.start();
  
  gainNode.gain.value = 0;
  
  oscillator.connect(gainNode);
  gainNode.connect(audioCtx.destination);
  
  
  
  // Setting up start position
  $scope.buttons = ['#red', '#blue', '#yellow', '#green'];
  $scope.strict = false;
  $scope.turn = "00";
  $scope.sequence = [];
  for (var i = 0; i < $scope.gameLength; i++) {
    var index = Math.floor(Math.random() * 4);
    $scope.sequence.push($scope.buttons[index]);
  };
  
  
  
  // Reset function. New sequence if strict mode or after winning
  $scope.reset = function() {
    $scope.userSequence = [];
    $scope.duration = 1000;
    $scope.i = 0;
    if ($scope.strict || $scope.turn === ":)") {
      $scope.sequence = [];
      for (var i = 0; i < $scope.gameLength; i++) {
        var index = Math.floor(Math.random() * 4);
        $scope.sequence.push($scope.buttons[index]);
      }
    }
    $scope.turn = "00";
    console.log($scope.sequence);
  };

  
  
  $scope.startGame = function() {
    if ($('.start-btn').hasClass('clickable')) {
      $scope.reset();
      $scope.playTurn(0);
    };
  };
  
  
  
  $scope.setStrict = function() {
    $scope.strict = !$scope.strict;
  };
  
  
  
  $scope.playTurn = function(i) {
    $('.start-btn').removeClass('clickable');
    $scope.turn = i<9 ? '0' + (i+1) : i+1;
    $timeout($scope.lightOn, $scope.duration, true, 0);
  };

   

  $scope.lightOn = function(i) {
    var id = $scope.sequence[i];
    oscillator.frequency.value = freqs[id];
    gainNode.gain.value = 1;
    $(id).addClass('active');
    $timeout($scope.lightOff, $scope.duration, true, i); 
  };
  
  

  $scope.lightOff = function(i) {
    gainNode.gain.value = 0;
    var id = $scope.sequence[i]
    $(id).removeClass('active');
    if (i === $scope.i) {
      $('.start-btn').addClass('clickable');
      $scope.userSequence = [];
      $('.button').addClass('clickable');
    } else {
      $timeout($scope.lightOn, $scope.duration, true, i+1);
    }
  };
  
  
  
  // Playing sound on mouse click
  $('.button').mousedown(function(){
    if ($('.button').hasClass('clickable')) {
      oscillator.frequency.value = freqs['#' + this.id];
      gainNode.gain.value = 1;
    };
  });
  
  
  
  // Stopping sound
  $('.button').mouseup(function(){
    gainNode.gain.value = 0;
  });
  
  
  
  $scope.click = function(id) {
    if ($('.button').hasClass('clickable')) {
      if ($scope.userSequence.length < $scope.gameLength) {
        $scope.userSequence.push(id);
      };
      if ($scope.userSequence.length === $scope.gameLength && $scope.userSequence[$scope.userSequence.length - 1] === $scope.sequence[$scope.userSequence.length - 1] && $scope.i === $scope.gameLength-1) {
        $scope.win();
        return;
      };
      if ($scope.userSequence[$scope.userSequence.length - 1] !== $scope.sequence[$scope.userSequence.length - 1]) {
        $scope.lose();
        return;
      };
      if ($scope.userSequence.length-1 === $scope.i && $scope.i !== $scope.gameLength-1) {
        $scope.i++;
        $scope.duration -= 25;
        $('.button').removeClass('clickable');
        $scope.playTurn($scope.i);
      };
    };
  };
  
  
  
  $scope.win = function() {
    $('.button').removeClass('clickable');
    $scope.turn = ":)";
    
    // If you don't start game in 5 sec it starts by itself
    function selfStart() {
      if ($scope.turn === ':)') {
        $scope.startGame();
      };
    };
    $timeout(selfStart, 5000, true);
  };
  
  
  
  $scope.lose = function() {
    $('.button').removeClass('clickable');
    $scope.turn = ":(";
    
    // If you don't start game in 5 sec it starts by itself
    function selfStart() {
      if ($scope.turn === ':(') {
        $scope.startGame();
      };
    };
    $timeout(selfStart, 5000, true);
  };
  
}]);
  
              
            
!
999px

Console