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="back">
  <div class="backCover"></div>
  <div class="seg topLeft">
    <div class="segCol box" id="blue"></div>
    <div class="segCov"></div>
  </div>

  <div class="seg topRight">
    <div class="segCol box" id="red"></div>
    <div class="segCov"></div>
  </div>

  <div class="seg bottomLeft">
    <div class="segCol box" id="green"></div>
    <div class="segCov"></div>
  </div>

  <div class="seg bottomRight">
    <div class="segCol box" id="yellow"></div>
    <div class="segCov"></div>
  </div>

  <div class="controllerBack">
    <h6 class="text-center">Simon®</h6>
  </div>

  <div class="display text-center">--</div>

  <div class="startButton">
    <div class="startInner"></div>
  </div>

  <div class="hardIndicatorBack">
    <div class="hardIndicator"></div>
  </div>

  <div class="hardButton">
    <div class="hardInner"></div>
  </div>

  <div class="power">
    <div class="powerSliderInner"></div>
  </div>

  <h5 class="count">COUNT</h5>
  <h5 class="start">START</h5>
  <h5 class="strict">STRICT</h5>
  <h5 class="off">OFF</h5>
  <h5 class="on">ON</h5>
  <h5 id="timeDisp" hidden><h5>
  
</div>
    
    <audio id="beepOne">
  <source src="https://s3.amazonaws.com/freecodecamp/simonSound1.mp3" type="audio/ogg"></source>
</audio>

  <audio id="beepTwo">
  <source src="https://s3.amazonaws.com/freecodecamp/simonSound2.mp3"></source>
</audio>

  <audio id="beepThree">
  <source src="https://s3.amazonaws.com/freecodecamp/simonSound3.mp3" type="audio/ogg"></source>
</audio>

  <audio id="beepFour">
  <source src="https://s3.amazonaws.com/freecodecamp/simonSound4.mp3" type="audio/ogg"></source>
</audio>

  <audio id="beepError">
  <source src="http://cd.textfiles.com/warcraftm/MCRAFT/SOUNDS/WARLIGHT.WAV" type="audio/ogg"></source>
</audio>
              
            
!

CSS

              
                html {
  background-color: #bec3c7;
}

.back {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translateY(-50%) translateX(-50%);
  width: 530px;
  height: 530px;
  & > .backCover {
    border-radius: 50%;
    width: 590px;
    height: 590px;
    top: -30px;
    left: -30px;
    position: absolute;
    background-color: black;
    box-shadow: 10px 10px 30px 10px #7c8c8d;
  }
  & .seg {
    width: 250px;
    height: 250px;
    position: absolute;
    & > .segCol {
      width: 250px;
      height: 250px;
      border-radius: 100% 0px 0px 0px;
      background-color: darkblue;
      position: absolute;
      bottom: 0px;
      right: 0px;
    }
    & > .segCov {
      width: 125px;
      height: 125px;
      background-color: black;
      position: absolute;
      bottom: 0px;
      right: 0px;
      border-radius: 100% 0px 0px 0px;
    }
    &.topLeft {
      left: 0px;
    }
    &.topRight {
      left: 280px;
      transform: rotate(90deg);
      & .segCol {
        background-color: darkred;
      }
    }
    &.bottomLeft {
      top: 280px;
      left: 0px;
      transform: rotate(270deg);
      & > .segCol {
        background-color: green;
      }
    }
    &.bottomRight {
      top: 280px;
      left: 280px;
      transform: rotate(180deg);
      & .segCol {
        background-color: orange;
      }
    }
  }
  & > .controllerBack {
    background-color: lightgray;
    width: 240px;
    height: 240px;
    z-index: 10;
    border-radius: 50%;
    top: 145px;
    left: 145px;
    position: absolute;
    & > h6 {
      font-family: "Rubik Mono One", sans-serif;
      font-size: 30px;
    }
  }
}

h6 {
  font-size: 40px;
  margin: 50px;
}

.display {
  color: darkred;
  font-size: 30px;
  width: 80px;
  height: 50px;
  border-radius: 15px;
  background-color: #2a0c0c;
  position: absolute;
  top: 260px;
  left: 165px;
  z-index: 20;
  &.active {
    color: red;
    background-color: #441010;
  }
}

.startButton {
  width: 36px;
  height: 36px;
  background-color: #202020;
  border-radius: 50%;
  position: absolute;
  top: 265px;
  left: 265px;
  z-index: 21;
  & > .startInner {
    width: 27px;
    height: 27px;
    border-radius: 50%;
    background-color: #545454;
    position: relative;
    top: 5px;
    left: 5px;
  }
  &.indent {
    position: absolute;
    transform: translateY(5%);
    box-shadow: 1px 1px 10px 1px black;
  }
  box-shadow: 5px 5px 20px 1px black;
}

.hardButton {
  width: 36px;
  height: 36px;
  background-color: #202020;
  border-radius: 50%;
  position: absolute;
  top: 265px;
  left: 320px;
  z-index: 21;
  &.indent {
    transform: translateY(5%);
    box-shadow: 1px 1px 10px 1px black;
  }
  & > .hardInner {
    width: 27px;
    height: 27px;
    border-radius: 50%;
    background-color: #545454;
    position: relative;
    top: 5px;
    left: 5px;
  }
  &.indent {
    position: absolute;
    transform: translateY(5%);
    box-shadow: 1px 1px 10px 1px black;
  }
  box-shadow: 5px 5px 20px 1px black;
}

.hardIndicatorBack {
  top: 246px;
  left: 330px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: black;
  position: relative;
  z-index: 22;
  .hardIndicator {
    position: relative;
    top: 2px;
    left: 2px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #584949;
  }
}

.power {
  width: 60px;
  height: 24px;
  border-radius: 5px;
  background-color: darkGray;
  position: absolute;
  top: 330px;
  left: 235px;
  z-index: 24;
  &.indent .powerSliderInner {
    left: 36px;
  }
  & > .powerSliderInner {
    width: 20px;
    height: 16px;
    border-radius: 3px;
    background-color: #2b4177;
    z-index: 25;
    position: relative;
    top: 4px;
    left: 4px;
    box-shadow: 2px 2px 20px 0.5px black;
  }
}

h5 {
  position: absolute;
  color: black;
  z-index: 25;
  font-size: 12px;
  &.count {
    top: 312px;
    left: 185px;
  }
  &.start {
    top: 312px;
    left: 270px;
  }
  &.strict {
    top: 312px;
    left: 320px;
  }
  &.off {
    top: 336px;
    left: 212px;
    font-size: 10px;
  }
  &.on {
    top: 336px;
    left: 300px;
    font-size: 10px;
  }
}

@media screen and (max-width: 500px) {
  .back {
    transform: scale(0.5) translateY(-100%) translateX(-100%);
  }
}
              
            
!

JS

              
                /* Type 'testEnding()' into console to demonstrate game ending funcitonality */

function beep(num) {
  switch (num) {
    case 0:
      beepOne.play();
      break;
    case 1:
      beepTwo.play();
      break;
    case 2:
      beepThree.play();
      break;
    case 3:
      beepFour.play();
      break;
    default:
      console.log("(18) ERROR -switch statement check()");
      console.log(num);
      break;
  }
}

var power = false;
var hardMode = false;
var gameInitiated = false;

$('.power').on('click', function() {
  powerToggle();
});

$('.hardButton').on('click', function() {
  modeToggle();
});

function powerToggle() {
  if (power) {
    $('.power').removeClass('indent');
    $('.display').html('--');
    $('.display').removeClass('active');
    gameInitiated = false;
    power = false;
    console.log("Turned Off");
  } else {
    $('.power').addClass('indent');
    $('.display').addClass('active');
    power = true;
    console.log("turned On");
  }
}
//console.log("Test 1");
function modeToggle() {
  switch (hardMode) {
    case true:
      $('.hardButton').addClass('indent');
      setTimeout(function(){
        $('.hardButton').removeClass('indent');
      }, 300);
      $('.hardIndicator').css('background-color', '#584949');
      console.log("(60) hardMode set to False");
      hardMode = false;
      break;
    case false:
      $('.hardButton').addClass('indent');
      setTimeout(function(){
        $('.hardButton').removeClass('indent');
      }, 300);
      $('.hardIndicator').css('background-color', 'red');
      console.log("(69) hardMode set to True");
      hardMode = true;
      break;
    default:
      console.log("(73) ERROR -switch statement strict");
      break;
  }
}

/*

1 = red
2 = green
3 = blue
4 = yellow

*/

var seq = [2, 0, 3];
var stage = 0;
var blinkDelay = 1000;
//console.log("Test 2");
function addStep() {
  var newNum = Math.round(Math.random() * 3);
  seq.push(newNum);
  console.log("(94) seq is: ");
  console.log(seq);
  stage++;
  if (stage == 21) {
    playerWins();
  } else {
    if (stage < 10) {
      stage = '0' + stage;
    }
    $('.display').html(stage);
  }
  
  //blinkDelay starts at 1000;
  //delayBetweenLights starts at 300;
  
  if (stage == 5) {
    blinkDelay = 850;
    delayBetweenLights = 270;
    console.log("(112) blinkDelay now: " + blinkDelay + " , delayBetweenLights now: " + delayBetweenLights);
  }
  if (stage == 9) {
    blinkDelay = 750;
    delayBetweenLights = 230;
    console.log("(112) blinkDelay now: " + blinkDelay + " , delayBetweenLights now: " + delayBetweenLights);
  }
  if (stage == 13) {
    blinkDelay = 650;
    delayBetweenLights = 250;
    console.log("(112) blinkDelay now: " + blinkDelay + " , delayBetweenLights now: " + delayBetweenLights);
  }
}

function blink(input) {
  //console.log("Blink called with input: " + input);

  var elem, lightColor, darkColor;

  switch (input) {
    case 'red':
    case 0:
      elem = 'red';
      lightColor = 'red';
      darkColor = 'darkred';
      beepOne.play();
      break;
    case 'green':
    case 1:
      elem = 'green';
      lightColor = 'lawngreen';
      darkColor = 'green';
      beepTwo.play();
      break;
    case 'blue':
    case 2:
      elem = 'blue';
      lightColor = 'blue';
      darkColor = 'darkblue';
      beepThree.play();
      break;
    case 'yellow':
    case 3:
      elem = 'yellow';
      lightColor = 'yellow';
      darkColor = 'orange';
      beepFour.play();
      break;
    default:
      console.log("ERROR -blink() switch statement");
      break;
  }

  //console.log("Blink funciton called for '" + elem + "' (" + input + ") ...");

  var box = document.getElementById(elem);
  $(box).css('background-color', lightColor);

  setTimeout(function() {
    $(box).css('background-color', darkColor);
  }, blinkDelay);

} // blink()
//console.log("Test 3");
var timeOut = 10000;
var timerStarted = false;
var currentTime = 0;

function startTimer() {

  if (timerStarted === false) {

    timerStarted = true;
    console.log("(166) startTimer called");

    $('#timeDisp').html(currentTime);

    setInterval(function() {

      currentTime++;
      $('#timeDisp').html(currentTime);

      if (currentTime >= 10 && power === true && gameInitiated === true) {
        console.log("(176) Timeout!");
        currentTime = 0;
        playerLoose();
      }

    }, 1000);
  } else {
    currentTime = 0;
    $('#timeDisp').html(currentTime);
  }
} // startTimer()
//console.log("Test 4");

$('.box').on('click', function() {
  currentTime = 0;
  $('#timeDisp').html(currentTime);
});

var delayBetweenLights = 300;
var largeDelay = delayBetweenLights + blinkDelay;
var delayAfterPlayer = 1000;

function show() {
  //console.log("show() called");

  canClickBox = false;
  var numItirations = seq.length;
  var currentItiration = 0;

  function sequenceExecute(indexInSeq) {
    // this actually calls the thing
    setTimeout(function() {

      //console.log("Calling blink from line 112, seq[indexInSeq] is: " + seq[indexInSeq]);
      if (power === true) {
        blink(seq[indexInSeq]);
      }
    }, delayBetweenLights);

    setTimeout(function() {
      currentItiration++;
      if (currentItiration < numItirations) {
        //console.log("(120) calling sequenceExecute for " + currentItiration);
        sequenceExecute(currentItiration);
      } else {
        canClickBox = true;
        currentTime = 0;
        $('#timeDisp').html(currentTime);
        canClickBox = true;
        //console.log("finished show()");
      }
    }, largeDelay);

  } // sequenceExecute()

  sequenceExecute(currentItiration);

} // show()
//console.log("Test 5");

var beepOne = document.getElementById('beepOne');
var beepTwo = document.getElementById('beepTwo');
var beepThree = document.getElementById('beepThree');
var beepFour = document.getElementById('beepFour');
var beepError = document.getElementById('beepError');

var canClickBox = false;

$('.startButton').on('click', function() {
  console.log("(243) Start button clicked");
  $('.startButton').addClass('indent');
  setTimeout(function(){
    $('.startButton').removeClass('indent');
  }, 300);
  if (power === true) {
    game();
  }
});

function manualBlink(num) {
  var elem, lightColor, darkColor;

  switch (num) {
    case 'red':
    case 0:
      elem = 'red';
      lightColor = 'red';
      darkColor = 'darkred';
      beepOne.play();
      break;
    case 'green':
    case 1:
      elem = 'green';
      lightColor = 'lawngreen';
      darkColor = 'green';
      beepTwo.play();
      break;
    case 'blue':
    case 2:
      elem = 'blue';
      lightColor = 'blue';
      darkColor = 'darkblue';
      beepThree.play();
      break;
    case 'yellow':
    case 3:
      elem = 'yellow';
      lightColor = 'yellow';
      darkColor = 'orange';
      beepFour.play();
      break;
    default:
      console.log("ERROR -blink() switch statement");
      break;
  }

  var box = document.getElementById(elem);
  $(box).css('background-color', lightColor);

  setTimeout(function() {
    $(box).css('background-color', darkColor);
  }, 418);
}
//console.log("Test 6");

$('#red').on('click', function() {
  if (canClickBox === true) {
    manualBlink(0);
    console.log("Click red");
    playerSeq.push(0);
    check(0);
  } else {
    console.log("Click with no permission");
  }
});

$('#green').on('click', function() {
  if (canClickBox === true) {
    manualBlink(1);
    console.log("Click green");
    playerSeq.push(1);
    check(1);
  } else {
    console.log("Click with no permission");
  }
});

$('#blue').on('click', function() {
  if (canClickBox === true) {
    manualBlink(2);
    console.log("Click blue");
    playerSeq.push(2);
    check(2);
  } else {
    console.log("Click with no permission");
  }
});

$('#yellow').on('click', function() {
  if (canClickBox === true) {
    manualBlink(3);
    console.log("Click yellow");
    playerSeq.push(3);
    check(3);
  } else {
    console.log("Click with no permission");
  }
});

var playerSeq = [];

function check(butNum) {

  console.log("Check called");

  var newItem = playerSeq.length - 1;
  if (seq[newItem] == playerSeq[newItem]) {
    console.log("The latest item is correct");
    beep(butNum);
  } else {
    console.log("The latest item is NOT correct");
    playerLoose();
  }

  console.log("seq: " + seq);
  console.log("player: " + playerSeq);
  if (seq.length == playerSeq.length) {
    addStep();
    playerSeq = [];
    setTimeout(function() {
      show();
    }, delayAfterPlayer);
  }
}
//console.log("Test 7");

function game() {
  gameInitiated = true;
  console.log("TEST -gameInitiated = true");
  seq = [];
  stage = 0;
  addStep();
  show();
  startTimer();
  //start the player timer

}

function playerLoose() {

  beepError.play();
  playerSeq = [];

  setTimeout(function() {
    if (hardMode === false) {
      setTimeout(function() {
        show();
      }, 1000);
    } else {
      seq = [];
      addStep();
      show();
    }
  }, 1000);
}
//console.log("Test 8");

function playerWins() {
  console.log("The Player Wins!");
  currentTime = 0;
  setTimeout(function() {
    console.log("Starting new game...");
    canClickBox = false;
    currentTime = 0;
    game();
  }, 3000);
}

function testEnding() {
  stage = 20;
  addStep();
}
              
            
!
999px

Console