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>

  <div class="circle-big"></div>
  <div id="places">
    <button id="place1" value=1 class="up-right color">
            <audio id="audio1" src="https://s3.amazonaws.com/freecodecamp/simonSound1.mp3"></audio>
        </button>
    <button id="place2" value=2 class="up-left color">
            <audio id="audio2" src="https://s3.amazonaws.com/freecodecamp/simonSound2.mp3"></audio>
        </button>
    <button id="place3" value=3 class="down-left color">
            <audio id="audio3" src="https://s3.amazonaws.com/freecodecamp/simonSound3.mp3"></audio>
        </button>
    <button id="place4" value=4 class="down-right color">
            <audio id="audio4" src="https://s3.amazonaws.com/freecodecamp/simonSound4.mp3"></audio>
        </button>
  </div>
  <div class="circle-small "> </div>

  <span id="strict">Strict</span>
  <div id="strict-button"></div>
  <span id="blind">Blind</span>
  <div id="blind-button"></div>
  <button id="start" class="toggle">Start</button>
  <button id="stop" class="toggle">Stop</button>
  <input type="text" class="" id="counter" readonly>

  <footer >
    <p>Coded by <a href="https://www.freecodecamp.com/tuliodnw" target="_blank">Tulio</a></p>
  </footer>

</body>
              
            
!

CSS

              
                .color {
  position: absolute;
  height: 170px;
  width: 170px;
  margin: auto;
  border: none;
}

button:focus {
  outline: 0;
}

footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  text-align: center;
}

.color:active {
  opacity: 0.7;
}

.circle-big {
  height: 380px;
  width: 380px;
  border-radius: 100%;
  background-color: #212121;
  margin: auto;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
}

.up-right {
  border-radius: 100% 0 0 0;
  background-color: #B71C1C;
  top: 0;
  left: 0;
  right: 185px;
  bottom: 185px;
}

.up-left{
  border-radius: 0 100% 0 0;
  background-color: #1c6ab7;
  top: 0;
  left: 185px;
  right: 0;
  bottom: 185px;
}

.down-right {
  border-radius: 0 0 100% 0;
  background-color: #12af23;
  top: 185px;
  left: 185px;
  right: 0;
  bottom: 0;
}

.down-left{
  border-radius: 0 0 0 100%;
  background-color: #FFCA28;
  top: 185px;
  left: 0;
  right: 185px;
  bottom: 0;
}

.circle-small {
  height: 150px;
  width: 150px;
  border-radius: 100%;
  margin: auto;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #EEEEEE;
  border: solid 10px #212121;
}

#strict {
  top: 0px;
  left: 110px;
  right: 0;
  bottom: 25px;
  margin: auto;
  position: absolute;
  height: 20px;
  width: 90px;
}

#blind {
  top: 50px;
  left: 110px;
  right: 0;
  bottom: 0px;
  margin: auto;
  position: absolute;
  height: 20px;
  width: 90px;
}

#strict-button {
  border-radius: 100%;
  height: 10px;
  width: 10px;
  background-color: #212121;
  top: 0px;
  left: 108px;
  right: 0;
  bottom: 25px;
  margin: auto;
  position: absolute;
  border: solid 2px #212121;
}

#blind-button {
  border-radius: 100%;
  height: 10px;
  width: 10px;
  background-color: #212121;
  top: 48px;
  left: 108px;
  right: 0;
  bottom: 0px;
  margin: auto;
  position: absolute;
  border: solid 2px #212121;
}

#counter {
  margin-top: 15px;
  height: 20px;
  width: 55px;
  border: none;
  background-color: #212121;
  color: red;
  border-radius: 2px;
  text-align: center;
  margin: auto;
  position: absolute;
  top: 45px;
  left: 0;
  right: 45px;
  bottom: 0;
  font-size: 0.8em;
}

.hardmode {
  background-color: black;
}

.redcalled {
  background-color: #e13e3e;
}

.bluecalled {
  background-color: #3e90e1;
}

.yellowcalled {
  background-color: #ffd75b;
}

.greencalled {
  background-color: #25e93a;
}

.toggle {
  text-align: center;
  background-color: #EEEEEE;
  border: solid 2px #212121;
  border-radius: 5px;
  margin: auto;
  position: absolute;
  top: 0;
  left: 0;
  right: 45px;
  bottom: 25px;
  height: 25px;
  width: 45px;
  margin: auto;
}

body {
  font-family: "Calibri";
  background-color: #EEEEEE;
}
              
            
!

JS

              
                var orden = [], hardmode = false, called = "",strict = false,pause = true, o = 0,inputUsuario = [];

//hide stop button so they dot overlap
$(document).ready(function() {
  document.getElementById("counter").value = "--";
  $("#stop").hide();
});

//tecla is the strict buton
$("#strict-button").click(function() {
  if (strict === false) {
    strict = true;
    $(this).css({
      "background-color": "red"
    });
  } else {
    strict = false;
    $(this).css({
      "background-color": "#212121"
    });
  }  
});

//tecla2 is the blind mode
$("#blind-button").click(function() {
  if (hardmode === false) {
    hardmode = true;
    $("#blind-button").css({
      "background-color": "red"
    });
    $("#place1,#place2,#place3,#place4").addClass("hardmode");
  } else {
    $("#place1,#place2,#place3,#place4").removeClass("hardmode");
    hardmode = false;
    $("#blind-button").css({
      "background-color": "#212121"
    });
  }
});

//start button, hides itself after click 
$("#start").click(function() {
   o=0;
  write();
  $("#start").hide();
  $("#stop").show();
});

//button that calls the stop function that resets the game
$("#stop").click(function() {
  stop();
  document.getElementById("counter").value = "--";
  $("#stop").hide();
});


//color fills the user array, also checks if the sequence is the same as ai, and check if the user won after doing 20 sequences
$(".color").click(function() {

  if (pause === false && orden.length > 0) {
    value = parseInt($(this).attr("value"));
    inputUsuario.push(value);
    var audio = document.getElementById("audio" + value);
    audio.play();

    if (orden[o] !== inputUsuario[o]) {
      if (strict !== true) {
        document.getElementById("counter").value = "mistake";
        inputUsuario = [];
        pause = true;
       $('#place1,#place2,#place3,#place4').prop('disabled', true);
        startTimer(0);
      } else {
        document.getElementById("counter").value = "game over";
        stop();
      }
    } else {

      if (inputUsuario.length === orden.length) {
        if (o != 14) {
          inputUsuario = [];
          pause = true;
      $('#place1,#place2,#place3,#place4').prop('disabled', true);
          write(0);
        } else {
          audio.src = "http://66.90.93.122/ost/pokemon-ten-years-of-pokemon/lcmjyyaprv/1-pokemon-theme-season-theme-.mp3";
          audio.play();
          $("#place1,#place2").css("background-color", "red");
          $("#place3,#place4").css("background-color", "white");
          $("#counter").css("width", "80px")
          document.getElementById("counter").value = "Catch'Em All";
          alert("YOU WON");
          stop();
        }
      }
    }
    o++;
  }
});

//write is the function that push the new color and calls the timer

function write(i) {
  if (pause === true) {
    o=0;
    pos = Math.floor((Math.random() * 4) + 1);
    orden.push(pos);
    document.getElementById("counter").value = orden.length;
    startTimer(0);
  }
}

//timer is the one that repeats all the color after a new input or if someone made a mistake
function startTimer(i) {
  timer = setInterval(function() {
    audio = document.getElementById("audio" + orden[i]);
    audio.play();
    switch (orden[i]) {
      case 1:
        called = "redcalled";
        break;
      case 2:
        called = "bluecalled";
        break;
      case 3:
        called = "yellowcalled";
        break;
      case 4:
        called = "greencalled";
    }
    $("#place" + orden[i]).addClass(called);
    setTimeout(function() {      
      //the 400-orden.length*9, its so the game is faster the longer you are, before i had it too fast
      $("#place1,#place2,#place3,#place4").removeClass(called);
    }, 400-orden.length*10);
    document.getElementById("counter").value = orden.length;
    
    //honestly i have no idea why i must put -2 and no -1, but it just worked
    if (i > orden.length - 2) {
      pause = false;
      $('#place1,#place2,#place3,#place4').prop('disabled', false);
      clearInterval(timer);
      o = 0;
    }
    i++;
  }, 1000-orden.length*20);
}

//stop is going to be a button that will stop the game so you can start again

function stop() {
  $("#place1,#place2,#place3,#place4").removeClass(called);
  $('#place1,#place2,#place3,#place4').prop('disabled', false);
  clearInterval(timer);
  pause = true;
  $("#stop").hide();
  $("#start").show();
  orden = [];
  inputUsuario = [];
}
              
            
!
999px

Console