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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <body ng-app="Simon">
  <div class="container" ng-controller="MainCtrl">
    <h1>Simon</h1>
    <div class="content">
      <div id="board-outline">
      <section id="board">
        <div class="col-md-6 btn color off" id="red"></div>

        <div class="col-md-6 btn color off" id="green"></div>

        <div id="interface">
          <span id="level">Level: {{level}}</span><span id="strict" class="btn">Strict Mode</span><span id="reset" class="btn">Reset</span>
        </div>

        <div class="col-md-6 btn color off" id="blue"></div>
        <div class="col-md-6 btn color off" id="yellow"></div>
      </section>
      </div>
    </div>
  </div>
</body>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Lobster);
html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  display: table;
}

.container {
  display: table-cell;
  text-align: center;
}

.content {
  display: inline-block;
  text-align: left;
}

#board-outline{
width:400px;
height:400px;
  background-color:black;
  border-radius:50%;
}

#board {
  width: 400px;
  height:400px;
}

h1 {
  margin: 30px;
  font-size: 4.5em;
  font-family: 'lobster';
}

.color {
  width: 200px;
  height: 200px;
  margin: 0 auto;
  border-radius:0;
  border:10px solid black;
}

#red {
  background-color: red;
  border-top-left-radius: 100%;
  border-bottom:5px solid black;
  border-right:5px solid black;
}

#green {
  background-color: #00ff00;
  border-top-right-radius: 100%;
  border-bottom:5px solid black;
  border-left:5px solid black;
}

#blue {
  background-color: #0000ff;
  border-bottom-left-radius: 100%;
  border-top:5px solid black;
  border-right:5px solid black;
}

#yellow {
  background-color: yellow;
  border-bottom-right-radius: 100%;
}

#interface {
  height: 200px;
  width: 200px;
  border-radius: 50%;
  background-color: #000;
  margin: 0 auto;
  position:relative;
  z-index:100;
  top:100px;
  color:white;
}

#level{
position:relative;
  top:-125px;
 
  font-size:2em;
  text-align:center;
  display:block;
}

#strict{
  position:relative;
  top:-125px;
  left:15px;
  display:inline;
  
}

#reset{
  position:relative;
  top:-125px;
  left:15px;
  display:inline;
}

.off {
  opacity: .7;
}

.on {
  opacity: 1.0;
}

.strictOn {
  background-color: #333;
  color: white;
}
              
            
!

JS

              
                var app = angular.module('Simon', []);
app.controller('MainCtrl', function($scope, $http) {
  $scope.strict = false;
  $scope.sequence = [];
  $scope.continue = true;
  $(document).ready(function() {
    $scope.speed = 1000;
    $scope.level = 1;
    $scope.count = 0;
    $scope.$apply();
    computer();

    $('#strict').click(function() {
      $(this).toggleClass('strictOn');
      $scope.strict = !$scope.strict;

      $scope.$apply();
    })

    $('.color').click(function() {
      var clicked = $(this).attr('id');
      switch (clicked) {
        case 'red':
          var audio = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3');
          audio.play();
          break;
        case 'green':
          var audio = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound2.mp3');
          audio.play();
          break;
        case 'blue':
          var audio = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound3.mp3');
          audio.play();
          break;
        case 'yellow':
          var audio = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound4.mp3');
          audio.play();
          break;
      }
      user(clicked);

    });

    $('#reset').click(function() {
      reset();

    });
  });

  /* User takes turn */
  var user = function(clicked) {

    /* User guesses right -- keep going */
    if (clicked == getColor($scope.sequence[$scope.count])) {
      if ($scope.count < $scope.sequence.length - 1) {
        $scope.count++;
        $scope.$apply();

      } else {
        levelup();
        switch ($scope.level) {
          case 5:
            $scope.speed = 800;

            break;
          case 9:
            $scope.speed = 600;
            break;
          case 13:
            $scope.speed = 400;
            break;

          case 20:
            alert("You won!");
            reset();
            break;
        }
        $scope.$apply();
      }

    }
    /* User guesses wrong */
    else {
      if ($scope.strict) {
        reset();
      } else {
        $scope.continue = false;
        $scope.count = 0;
        $scope.$apply();
        computer();
      }

    }

  };

  var levelup = function() {
    $scope.count = 0;
    $scope.level++;

    var num = Math.floor(Math.random() * 4);
    $scope.sequence.push(num);
    animate($scope.sequence);
    $scope.$apply();
  }

  /* Computer takes turn */
  var computer = function() {
    if ($scope.continue) {
      var num = Math.floor(Math.random() * 4);
      $scope.sequence.push(num);

    }
    animate($scope.sequence);
    $scope.continue = true;

  }

  /* Sequence is lit up */
  function animate(sequence) {
    var i = 0;
    var interval = setInterval(function() {
      light(getColor(sequence[i]));

      i++;
      if (i >= sequence.length) {
        clearInterval(interval);
      }
    }, $scope.speed);
  }

  var light = function(color) {
    $('#' + color).toggleClass('on');
    setTimeout(function() {
      $('#' + color).toggleClass('on');
    }, $scope.speed);
  }

  /* Reset */
  var reset = function() {
    $scope.sequence = [];
    $scope.continue = true;
    $scope.level = 1;
    $scope.count = 0;
    $scope.$apply();
    computer();
  }

  /* Translate numbers to colors */
  var getColor = function(num) {
    var color;
    switch (num) {
      case 0:
        color = 'red';
        var audio = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3');
        audio.play();
        break;

      case 1:
        color = 'green';
        var audio = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound2.mp3');
        audio.play();
        break;

      case 2:
        color = 'blue';
        var audio = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound3.mp3');
        audio.play();
        break;
      case 3:
        color = 'yellow';
        var audio = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound4.mp3');
        audio.play();
        break;
    }
    return color;
  }

});
              
            
!
999px

Console