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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                .container
      .green.normal-green
      .red.normal-red
      .yellow.normal-yellow
      .blue.normal-blue
      .controls
        h1 Simon
        ul
          li
            p#count --
            p COUNT
          li
            button.control.start
            p START
          li
            button.control.strict
            p STRICT

          button#reset Reset
              
            
!

CSS

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

.container
  margin: 5% auto
  background: #000
  position: relative
  font-family: 'Arvo', serif
  height: 500px
  width: 500px
  border-radius: 50%
  box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23)
  z-index: 1

.green
  position: absolute
  top: 17px
  left: 17px
  height: 225px
  width: 225px
  border-radius: 100% 0 0 0
  z-index: 5

.red
  position: absolute
  top: 17px
  right: 17px
  height: 225px
  width: 225px
  border-radius: 0 100% 0 0
  z-index: 5

.yellow
  position: absolute
  bottom: 17px
  left: 17px
  height: 225px
  width: 225px
  border-radius: 0 0 0 100%
  z-index: 5

.blue
  position: absolute
  bottom: 17px
  right: 17px
  height: 225px
  width: 225px
  border-radius: 0 0 100% 0
  z-index: 5

.controls
  background: #dfdfdf
  box-sizing: border-box
  border: 15px solid #000
  border-radius: 100%
  height: 300px
  width: 300px
  position: absolute
  top: 20%
  left: 20%
  z-index: 10

h1
  margin: 15% 25% 0 16%
  font-size: 60px
  font-weight: bold
ul
  list-style: none
  margin: 0 0

li
  font-size: 14px
  display: inline-block
  margin-top: 10px
  text-align: center

.control
  height: 30px
  width: 30px
  border-radius: 100%

#count
  height: 30px
  width: 60px
  margin: 5px 10px 0 10px
  color: #f60909
  text-align: center
  font-size: 28px
  background: #330f0f
  border: 4px solid #2e2e2f
  border-radius: 10px
  box-shadow: 0 2px 0 2px rgba(0, 0, 0, 0.7)

button
  display: block

  &:focus
    outline: none

  &:active
    transform: translateY(2px)

.start
  background: #f00832
  margin-left: 9px
  box-shadow: 0 2px 0 2px rgba(0, 0, 0, 0.7)

.strict
  background: #f3f70b
  margin-left: 11px
  box-shadow: 0 2px 0 2px rgba(0, 0, 0, 0.7)

#reset
  margin-left: 28%
  margin-top: 10px
  width: 60px
  height: 30px
  background: url("http://bgfons.com/uploads/aluminum/aluminum_texture1738.jpg")
  color: black
  border-radius: 20px
  box-shadow: 0 2px 0 2px rgba(0, 0, 0, 0.7)

  &:focus, &:active
    outline: none

  &:active
    top: 5px

.highlight-green
  background: #41f664

.normal-green
  background: #34ba1c

.highlight-red
  background: #f73c36

.normal-red
  background: #cb1818

.highlight-yellow
  background: #fbf21f

.normal-yellow
  background: #c6c412

.highlight-blue
  background: #5158f9

.normal-blue
  background: #2738d0

              
            
!

JS

              
                var playerArr = [];
var computerArr = [];
var computerPlayedArr = [];
var gameStyle = '';
var counter = 1;
var count = 0;

$(document).ready(function() {

  function randomComputerArr() {
    for (var i = 0; i < 20; i++) {
      computerArr[i] = Math.ceil(Math.random() * 4);
    }
  }

  function computerTurn() {
    var interval = setInterval(function() {
      if (computerArr[count] === 1) {
        computerPlayedArr.push(1);
        highlightButton(1);
      } else if (computerArr[count] === 2) {
        computerPlayedArr.push(2);
        highlightButton(2);
      } else if (computerArr[count] === 3) {
        computerPlayedArr.push(3);
        highlightButton(3);
      } else {
        computerPlayedArr.push(4);
        highlightButton(4);
      }
      count++;
      if (count >= counter) {
        clearInterval(interval);
      }
    }, 600);

  }

  function highlightButton(color) {
    var greenSound = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3');
    var redSound = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound2.mp3');
    var yellowSound = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound3.mp3');
    var blueSound = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound4.mp3');

    switch (color) {
      case 1:
        $('.green').removeClass('normal-green');
        $('.green').addClass('highlight-green');
        greenSound.play();
        setTimeout(function() {
          $('.green').removeClass('highlight-green');
          $('.green').addClass('normal-green');
        }, 300);
        break;
      case 2:
        $('.red').removeClass('normal-red');
        $('.red').addClass('highlight-red');
        redSound.play();
        setTimeout(function() {
          $('.red').removeClass('highlight-red');
          $('.red').addClass('normal-red');
        }, 300);
        break;
      case 3:
        $('.yellow').removeClass('normal-yellow');
        $('.yellow').addClass('highlight-yellow');
        yellowSound.play();
        setTimeout(function() {
          $('.yellow').removeClass('highlight-yellow');
          $('.yellow').addClass('normal-yellow');
        }, 300);
        break;
      case 4:
        $('.blue').removeClass('normal-blue');
        $('.blue').addClass('highlight-blue');
        blueSound.play();
        setTimeout(function() {
          $('.blue').removeClass('highlight-blue');
          $('.blue').addClass('normal-blue');
        }, 300);
        break;
      default:
        break;
    }
  }

//checkWin function inspired by the Happy Coder Youtube channel
//https://www.youtube.com/watch?v=4pfvy_A5ceE
  function checkWin() {
    
    if (playerArr.length === computerPlayedArr.length) {
      if (playerArr.join() === computerPlayedArr.join()) {
        if (counter === 20) {
          setTimeout(function() {
            alert('Winner!!');
            reset();
          }, 1000);
        } else {
          setTimeout(function() {
            computerPlayedArr = [];
            playerArr = [];
            counter++;
            $('#count').text(counter);
            count = 0;
            computerTurn();
          }, 1000);
        }
      } else {
        if (gameStyle === 'strict') {
          $('#count').text('!!');
          setTimeout(function() {
            reset();
          }, 1000);
        } else {
          computerPlayedArr = [];
          playerArr = [];
          count = 0;
          computerTurn();
        }
      }
    }
  }

  function reset() {
    computerArr = [];
    computerPlayedArr = [];
    playerArr = [];
    count = 0;
    $('#count').text('--');
    counter = 1;
  }

  $('.start').on('click', function() {
    $('#count').text(counter);
    randomComputerArr();
    computerTurn();
  });

  $('.green').on('click', function() {
    playerArr.push(1);
    highlightButton(1);
    checkWin();
  });

  $('.red').on('click', function() {
    playerArr.push(2);
    highlightButton(2);
    checkWin();
  });

  $('.yellow').on('click', function() {
    playerArr.push(3);
    highlightButton(3);
    checkWin();
  });

  $('.blue').on('click', function() {
    playerArr.push(4);
    highlightButton(4);
    checkWin();
  });


  $('.strict').on('click', function() {
    gameStyle = 'strict';
  });

  $('#reset').on('click', function() {
    reset();
  });

});

              
            
!
999px

Console