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

              
                <audio id = "blueSound" src = "https://s3.amazonaws.com/freecodecamp/simonSound1.mp3" preload = "auto"></audio>
<audio id = "yellowSound" src = "https://s3.amazonaws.com/freecodecamp/simonSound2.mp3" preload = "auto"></audio>
<audio id = "redSound" src = "https://s3.amazonaws.com/freecodecamp/simonSound3.mp3" preload = "auto"></audio>
<audio id = "greenSound" src = "https://s3.amazonaws.com/freecodecamp/simonSound4.mp3" preload = "auto"></audio>


<div class = "container-fluid">
  <div class = "row">
    <div class = "col-md-3"></div>
    <div class = "col-md-6">
      <div id = "main" class = "main">
        <div id = "center" class = "center">
          <h1 id = "title" class = "title">Simon</h1>
          <div id = "display" class = "left display">00</div>
          <button id = "startBtn" class = "left startBtn btn console"></button>
          <button id = "strictBtn" class = "left strictBtn btn console"></button>
          <div id = "strictIndic" class = "left strictIndic"></div>
          <br><br><br>
          <h3 id = "count" class = "left count">Count</h3>
          <h3 id = "start" class = "left start">Start</h3>
          <h3 id = "strict" class = "left strict">Strict</h3>
          <br>
          <h3 id = "off" class = "left off">Off</h3>
          <div id = "switch" class = "left switch">
            <div id = "offSwitch" class = "offSwitch"></div>
            <div id = "onSwitch" class = "onSwitch activeSwitch"></div>
          </div>
          <h3 id = "on" class = "left on">On</h3>
        </div>
        <button id = "green" class = "green btn"></button>
        <button id = "red" class = "red btn"></button>
        <button id = "yellow" class = "yellow btn"></button>
        <button id = "blue" class = "blue btn"></button>
      </div>
    </div>
    <div class = "col-md-3"></div>
  </div>
</div>
              
            
!

CSS

              
                body{
  background-color: brown;
}
.main{
  background-color:#1A1A1A;
  border-radius:50%;
  height: 500px;
  width: 500px;
  margin: 20px auto 20px auto;
  position:absolute;
  box-shadow: 2px 2px 10px black, -1px -1px 8px black inset;
}

button:focus{
  border:none !important;
  box-shadow:none !important;
}

.console:focus{
  box-shadow: 1px 1px 3px black, -1px -1px 3px black inset !important;
}

.green{
  width: 40%;
  height: 40%;
  background: #27A414;
  border-radius: 110% 0 0 0;
  position:absolute;
  left:30px;
  top:30px;
  z-index: 500;
}

.activeGreen{
  background-color: #36DE1C;
  box-shadow: 0 0 10px #36DE1C;
}

.red{
  width: 40%;
  height: 40%;
  background: #A41414;
  border-radius: 0 110% 0 0;
  position:absolute;
  right:30px;
  top:30px;
  z-index: 500;
}

.activeRed{
  background-color: #DE1C1C;
  box-shadow: 0 0 10px #DE1C1C;
}

.yellow{
  width: 40%;
  height: 40%;
  background: #A0A414;
  border-radius: 0 0 0 110%;
  position:absolute;
  left:30px;
  bottom:30px;  
  z-index: 500;
}

.activeYellow{
  background-color: #DEDB1C;
  box-shadow: 0 0 10px #DEDB1C;
}

.blue{
  width: 40%;
  height: 40%;
  background: #142AA4;
  border-radius: 0 0 110% 0;
  position:absolute;
  right:30px;
  bottom:30px; 
  z-index: 500;
}

.activeBlue{
  background-color: #1C28DE;
  box-shadow: 0 0 10px #1C28DE;
}

.center{
  background-color:white;
  position:relative;
  display:block;
  left: 125px;
  top: 125px;
  height: 250px;
  width: 250px;
  z-index: 1000;
  border-radius: 50%;
  border: 25px solid #1A1A1A;
}

.left{
  float:left;
}

.title{
  text-align:center;
  margin: 5px auto 0px auto;
}

.display{
  height:50px;
  font-size:30px;
  color:orange;
  background-color:#1A1A1A;
  width: 40px;
  text-align: center;
  border-radius: 10px;
  margin: 20px 0px 0px 20px;
}

div > h3 {
  pointer-events:none;
  display: inline;
  font-size: 15px;
  margin-left: 18px;
}

.count{
  width: 45px;
}

.start{
  width: 45px;
}

.startBtn{
  background-color:red;
  border-radius: 50%;
  height: 35px;
  width: 35px;
  box-shadow: 1px 1px 3px black, -1px -1px 3px black inset;
  border:none;
  margin: 30px 0px 0px 20px;
}

.strictIndic{
  border-radius:50%;
  width: 15px;
  height: 15px;
  background-color:gray;
  margin: 15px 0px 0px 7px;
  position:relative;
  top: -8px;
  right: 30px;
}

.strictActive{
  background-color:lime;
  box-shadow: 0 0 6px lime;
}

.strictBtn{
  border-radius: 50%;
  background-color: yellow;
  height: 35px;
  width: 35px;
  box-shadow: 1px 1px 3px black, -1px -1px 3px black inset;
  border:none;
  margin: 30px 0px 0px 20px;
}

.strict{
  margin-left: 11px;
}

.off{
  margin-left: 30px;
  margin-top: 8px;
}

.on{
  margin-top: 8px;
  margin-left: 12px;
}

.switch{
  background-color:#1A1A1A;
  left:65px;
  width: 70px;
  height: 35px;
  border-radius: 10px;
  margin-left:12px;
}

.offSwitch{
  background-color:#1A1A1A;
  border-radius: 10px;
  width:35px;
  height:35px;
  float:left;
}

.onSwitch{
  background-color:#1A1A1A;
  border-radius: 10px;
  width:35px;
  height:35px;
  float:left;
}

.activeSwitch{
  background-color:purple;
}
              
            
!

JS

              
                var count = 0;
var compArr = [];
var playerArr = [];
var isRunning = false;

function start(){
  if ($("#onSwitch").hasClass("activeSwitch")){
    playerArr = [];
    compArr = [];
    count = 1;
    $("#display").text("0" + count);
    for (i=0; i<20; i++){
      var num = Math.floor((Math.random() * 4) + 1);
      if (num == 1){
        compArr.push("green");
      } else if (num == 2){
        compArr.push("red");
     } else if (num == 3){
       compArr.push("yellow");
     } else if (num == 4){
       compArr.push("blue");
     }
    }
  }
}

function game(){
  var i = 0;
  var test = setInterval(function(){
      if (i==count){
        isRunning = false;
        clearInterval(test);
        return;
      }
      isRunning = true;
      if(compArr[i] == "green"){
        $("#green").addClass("activeGreen");
        $("#greenSound").get(0).play();
        setTimeout(function(){
          $("#green").removeClass("activeGreen");
        }, 500);
      } else if (compArr[i] == "red"){
        $("#red").addClass("activeRed");
        $("#redSound").get(0).play();
        setTimeout(function(){
          $("#red").removeClass("activeRed");
        }, 500);
      } else if (compArr[i] == "yellow"){
        $("#yellow").addClass("activeYellow");
        $("#yellowSound").get(0).play();
        setTimeout(function(){
          $("#yellow").removeClass("activeYellow");
        }, 500);
      } else if (compArr[i] == "blue"){
        $("#blue").addClass("activeBlue");
        $("#blueSound").get(0).play();
        setTimeout(function(){
          $("#blue").removeClass("activeBlue");
        }, 500);
      }
    i++;
    playerArr = [];
  }, 800);
}

function normalFailure(){
  isRunning = true;
  $("#display").text("!!");
  playerArr = [];
    setTimeout(function(){
      $("#display").text("");
        setTimeout(function(){
          $("#display").text("!!");
          setTimeout(function(){
            if(count<10){
              $("#display").text("0" + count);
            } else {
              $("#display").text(count);
            }
            setTimeout(function(){game();}, 500);
          }, 500);
        }, 500);
    }, 500);
}

function strictFailure(){
  isRunning = true;
  $("#display").text("!!");
  count = 0;
  compArr = [];
  playerArr = [];
    setTimeout(function(){
      $("#display").text("");
        setTimeout(function(){
          $("#display").text("!!");
          setTimeout(function(){
            $("#display").text("00");
            setTimeout(function(){
              alert("You have lost. Try again!");
              isRunning = false;
            }, 300);
          }, 300);
        }, 300);
    }, 300);
}

function win(){
  $("#display").text("!!");
  count = 0;
  compArr = [];
  playerArr = [];
    setTimeout(function(){
      $("#display").text("");
        setTimeout(function(){
          $("#display").text("!!");
          setTimeout(function(){
            $("#display").text(":)");
            setTimeout(function(){
              alert("Congratulations! You have won!");
              isRunning = false;
              isBtnRunning = false;
            }, 300);
          }, 300);
        }, 300);
    }, 300);  
}

$("#startBtn").click(function(){
  if(isRunning === true){
    return;
  }
  start();
  game();
});

$("#strictBtn").click(function(){
  if($("#onSwitch").hasClass("activeSwitch")){
    if($("#strictIndic").hasClass("strictActive")){
     $("#strictIndic").removeClass("strictActive");
    } else{
     $("#strictIndic").addClass("strictActive");
    }
  }
});

$("#onSwitch").click(function(){
  if (isRunning === true){
    return;
  }
  if($("#onSwitch").hasClass("activeSwitch")){
    $("#onSwitch").removeClass("activeSwitch");
    $("#offSwitch").addClass("activeSwitch");
    $("#display").text("");
    $("#strictIndic").removeClass("strictActive");
  } else {
    isRunning = true;
    $("#offSwitch").removeClass("activeSwitch");
    $("#onSwitch").addClass("activeSwitch");
    $("#display").text("--");
    count = 0;
    compArr = [];
    playerArr = [];
      setTimeout(function(){
        $("#display").text("");
          setTimeout(function(){
            $("#display").text("--");
            setTimeout(function(){
              $("#display").text("00");
              isRunning = false;
            }, 300);
          }, 300);
      }, 300);
  }
});

$("#offSwitch").click(function(){
  if (isRunning === true){
      return;
    }
  if($("#onSwitch").hasClass("activeSwitch")){
    $("#onSwitch").removeClass("activeSwitch");
    $("#offSwitch").addClass("activeSwitch");
    $("#display").text("");
    $("#strictIndic").removeClass("strictActive");
  } else {
    $("#offSwitch").removeClass("activeSwitch");
    $("#onSwitch").addClass("activeSwitch");
    $("#display").text("--");
    count = 0;
    compArr = [];
    playerArr = [];
      setTimeout(function(){
        $("#display").text("");
          setTimeout(function(){
            $("#display").text("--");
            setTimeout(function(){
              $("#display").text("00");
            }, 300);
          }, 300);
      }, 300);
  }
});

var isBtnRunning = false;

$("#green").click(function(){
  if(isRunning === true){
    return;
  }
  if($("#onSwitch").hasClass("activeSwitch")){
    if(isRunning === false){
      if (isBtnRunning === true){
        return;
      }
      isBtnRunning = true;
      if(count>0){
        $("#green").addClass("activeGreen");
        $("#greenSound").get(0).play();
         setTimeout(function(){
           $("#green").removeClass("activeGreen");
           isBtnRunning = false;
         }, 500);
        playerArr.push("green");
        for(i=0; i<playerArr.length; i++){
          if (playerArr[i] !== compArr[i]){
            if ($("#strictIndic").hasClass("strictActive")){
              strictFailure();
              return;
            } else {
              normalFailure();
              return;
            }
          } else if(i == count-1){
            count++;
            if (count<10){
              $("#display").text("0" + count);
            }else if(count>20){
              win();
            }else{
              $("#display").text(count);
            }
            game();
            playerArr = [];
          }
        }
      }
    }
  }
});

$("#red").click(function(){
  if(isRunning === true){
    return;
  }
  if($("#onSwitch").hasClass("activeSwitch")){
    if(isRunning === false){
      if (isBtnRunning === true){
        return;
      }
      isBtnRunning = true;
      if(count>0){
        $("#red").addClass("activeRed");
        $("#redSound").get(0).play();
         setTimeout(function(){
           $("#red").removeClass("activeRed");
           isBtnRunning = false;
         }, 500);
        playerArr.push("red");
        for(i=0; i<playerArr.length; i++){
          if (playerArr[i] !== compArr[i]){
            if ($("#strictIndic").hasClass("strictActive")){
              strictFailure();
              return;
            } else {
              normalFailure();
              return;
            }
          } else if(i == count-1){
            count++;
            if (count<10){
              $("#display").text("0" + count);
            }else if(count>20){
              win();
            }else{
              $("#display").text(count);
            }
            game();
            playerArr = [];
          }
        }
      }
    }
  }
});

$("#yellow").click(function(){
  if(isRunning === true){
    return;
  }
  if($("#onSwitch").hasClass("activeSwitch")){
    if(isRunning === false){
      if (isBtnRunning === true){
        return;
      }
      isBtnRunning = true; 
      if(count>0){
        $("#yellow").addClass("activeYellow");
        $("#yellowSound").get(0).play();
         setTimeout(function(){
           $("#yellow").removeClass("activeYellow");
           isBtnRunning = false;
         }, 500);
        playerArr.push("yellow");
        for(i=0; i<playerArr.length; i++){
          if (playerArr[i] !== compArr[i]){
            if ($("#strictIndic").hasClass("strictActive")){
              strictFailure();
              return;
            } else {
              normalFailure();
              return;
            }
          } else if(i == count-1){
            count++;
            if (count<10){
              $("#display").text("0" + count);
            }else if(count>20){
              win();
            }else{
              $("#display").text(count);
            }
            game();
            playerArr = [];
          }
        }
      }
    }
  }
});

$("#blue").click(function(){
  if(isRunning === true){
    return;
  }
  if($("#onSwitch").hasClass("activeSwitch")){
    if(isRunning === false){
      if (isBtnRunning === true){
        return;
      }
      isBtnRunning = true;
      if(count>0){
        $("#blue").addClass("activeBlue");
        $("#blueSound").get(0).play();
         setTimeout(function(){
           $("#blue").removeClass("activeBlue");
           isBtnRunning = false;
         }, 500);
        playerArr.push("blue");
        for(i=0; i<playerArr.length; i++){
          if (playerArr[i] !== compArr[i]){
            if ($("#strictIndic").hasClass("strictActive")){
              strictFailure();
              return;
            } else {
              normalFailure();
              return;
            }
          } else if(i == count-1){
            count++;
            if (count<10){
              $("#display").text("0" + count);
            }else if(count>20){
              win();
              return;
            }else{
              $("#display").text(count);
            }
            game();
            playerArr = [];
          }
        }
      }
    }
  }
});

$(".btn").click(function(){
  document.getElementById("strictBtn").focus();
});
              
            
!
999px

Console