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

Packages

Add Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import or require. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="rim">
  <div class="options">
    <h1>Simon</h1>
    <div class = "row">
    <div class="count off">
      <div class="count-box">--
      </div>
      <p></p>
    </div>
      <button class = "opt-btn" id = "start">Start</button>
      
      <button class = "opt-btn" id = "strict">Strict</button>
    </div>
  </div>

  <div class="row">
    <div class=" container green unclickable" id ="green"></div>
    <div class="container red unclickable" id = "red"></div>
  </div>
  <div class="row">
    <div class="container yellow unclickable" id = "yellow"></div>
    <div class="container blue unclickable" id ="blue"></div>
  </div>
</div>
            
          
!
            
               @import url('https://fonts.googleapis.com/css?family=Sacramento');
body{
  text-align: center;
  
    background-image: -webkit-repeating-radial-gradient(center center, rgba(0,0,0,.2), rgba(0,0,0,.2) 1px, transparent 1px, transparent 100%);
  background-image: -moz-repeating-radial-gradient(center center, rgba(0,0,0,.2), rgba(0,0,0,.2) 1px, transparent 1px, transparent 100%);
  background-image: -ms-repeating-radial-gradient(center center, rgba(0,0,0,.2), rgba(0,0,0,.2) 1px, transparent 1px, transparent 100%);
  background-image: repeating-radial-gradient(center center, rgba(0,0,0,.2), rgba(0,0,0,.2) 1px, transparent 1px, transparent 100%);
  -webkit-background-size: 3px 3px;
  -moz-background-size: 3px 3px;
  background-size: 3px 3px;
}
.rim{
  width: 550px;
  height: 550px;
  position: fixed;
  top: 50%;
  left: 50%;
  margin-top: -250px;
  margin-left: -250px;
  background-color: black;
  padding-top: 17.5px;
  border-radius: 50%;
}
.container {
  width: 250px;
  height: 250px;
  
}
.unclickable {
  cursor: default;
  pointer-events: none;
}
.green {
  background-color: green;
  border-left: 25px solid green;
  border-top: 25px solid green;
  border-right: 12.5px solid green;
  border-bottom: 12.5px solid green;
  border-top-left-radius: 100%;
  margin-right: -15px;
  
}
.green-active{
  background-color: lime;
  border-left: 25px solid lime;
  border-top: 25px solid lime;
  border-right: 12.5px solid lime;
  border-bottom: 12.5px solid lime;
  border-top-left-radius: 100%;
  margin-right: -15px;
}
.red{
  background-color: red;
  border-left: 12.5px solid red;
  border-top: 25px solid red;
  border-right: 25px solid red;
  border-bottom: 12.5px solid red;
  border-top-right-radius: 100%;
}
.red-active{
   background-color: #ff294e ;
  border-left: 12.5px solid #ff294e;
  border-top: 25px solid #ff294e;
  border-right: 25px solid #ff294e;
  border-bottom: 12.5px solid #ff294e;
  border-top-right-radius: 100%;
}
.yellow {
  margin-top: 15px;
  margin-right: -15px;
  background-color: yellow;
  border-left: 25px solid yellow;
  border-top: 12.5px solid yellow;
  border-right: 12.5px solid yellow;
  border-bottom: 25px solid yellow;
  border-bottom-left-radius: 100%;
}
.yellow-active{
  margin-top: 15px;
  margin-right: -15px;
  background-color:  #f7ff89  ;
  border-left: 25px solid  #f7ff89  ;
  border-top: 12.5px solid  #f7ff89  ;
  border-right: 12.5px solid  #f7ff89  ;
  border-bottom: 25px solid  #f7ff89  ;
  border-bottom-left-radius: 100%;
}
.blue {
  margin-top: 15px;
  background-color: blue;
  border-left: 12.5px solid blue;
  border-top: 12.5px solid blue;
  border-right: 25px solid blue;
  border-bottom: 25px solid blue;
  border-bottom-right-radius: 100%;
}
.blue-active{
  margin-top: 15px;
  background-color: #00adff;
  border-left: 12.5px solid #00adff;
  border-top: 12.5px solid #00adff;
  border-right: 25px solid #00adff;
  border-bottom: 25px solid #00adff;
  border-bottom-right-radius: 100%;
}

.options {
  background-color: white;
  position: absolute;
  width: 250px;
  height: 250px;
  border-radius: 50%;
  top: 50%;
  left: 50%;
  margin-top: -125px;
  margin-left: -125px;
  border: 17.5px solid black;
  padding-top: 25px;
}
.count-box {
  width: 50px;
  height: 50px;
  border: solid black;
  margin-left: 12.5px;
  font-size: 25px;
  padding-top: 5px;
  
}
.count {
  margin-left: 25px;
  width: 75px;
  text-align: center;
  
}
.off {
  color: lightgrey;
}
.opt-btn {
  height: 50px;
  width: 50px;
  border-radius: 50%;
  border: solid 1px;
}
#start{
  margin-right: 10px;
  background-color: red;
}
#strict {
  margin-right: 25px;
  background-color: yellow;
}
h1 {
    font-family: 'Sacramento', cursive;
}
            
          
!
            
              $(document).ready(function() {
  var colorkey = { 0: "green", 1: "red", 2: "yellow", 3: "blue" };
  var count = 1;
  var cSeq = [];
  var uSeq = [];
  var wait;
  var gsnd = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound1.mp3");
  var rsnd = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound2.mp3");
  var ysnd = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound3.mp3");
  var bsnd = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound4.mp3");

  //function to light up buttons
  var ga = function(color) {
    wait = "on";
    $("#" + color).removeClass(color);
    $("#" + color).addClass(color + "-active");
    var snd = {"green":gsnd, "red":rsnd, "yellow":ysnd, "blue":bsnd};
    snd[color].play();
    
    setTimeout(function() {
      $("#" + color)
        .removeClass(color + "-active").addClass(color);
        
    
    }, 900);
   
    
  };

  //
  //computer sequence
  var computerSeq = function(count){
   
    $(".count-box").html(count);
    $(".container").addClass("unclickable");
    uSeq = [];
    var temp;
    if (cSeq.length + 1 === count) {
      temp = Math.floor(Math.random() * Math.floor(4));
      cSeq.push(colorkey[temp]);

      var i = 0;
      var f = function() {
        
        ga(cSeq[i]);
        i++;
        if (i < cSeq.length + 1) {
          setTimeout(f, 900);
          
        }
        };
      
      f();
      } else if (cSeq.length === count){
        var i = 0;
      var f = function() {
        
        ga(cSeq[i]);
        i++;
        if (i < cSeq.length + 1) {
          setTimeout(f, 900);
          
        }
        };
      
      f();
      }
     
    $(".container").removeClass("unclickable");
  };
  
  

  //
  //Start button functions
  $("#start").click(function() {
    
    //establishes reset button
    if ($("#start").hasClass("reset") === false) {
      computerSeq(count);
      $("#start").html('<i class="fa fa-refresh" aria-hidden="true"></i>');
      $("#start").addClass("reset"); //creates identifier for reseting game
      //prevents color buttons from working before clicking start
      $(".container").removeClass("unclickable");
    } else {
      //resets/reloads page --->there's probably a faster way to reset the game
      window.location.reload(true);
    }
  });

  //
  //strict mode code
  $("#strict").click(function() {
    if ($("#strict").hasClass("on") === false) {
      $("#strict")
        .html('<i class="fa fa-times" aria-hidden="true"></i>')
        .addClass("on");
    } else {
      $("#strict")
        .removeClass("on")
        .html("Strict");
    }
  });
  //
  //

  //
  //color button functions

  $("#green").click(function() {
    ga("green");
    uSeq.push("green");
  });

  $("#red").click(function() {
    ga("red");
    uSeq.push("red");
  });
  $("#blue").click(function() {
    ga("blue");
    uSeq.push("blue");
  });

  $("#yellow").click(function() {
    ga("yellow");
    uSeq.push("yellow");
  });
  //compairs arrays
  var arraysEqual = function(arr1, arr2) {
    if(arr1.length !== arr2.length)
        return false;
    for(var i = arr1.length; i--;) {
        if(arr1[i] !== arr2[i])
            return false;
    }

    return true;
};
  // checks if user satisfied sequence after each button press
  $(".container").click(function(){
    console.log(uSeq);
    console.log(cSeq);
    if (arraysEqual(cSeq, uSeq)) {
      count++;  
      var j = 0; var max = 2;
      var cont = function(){
        if (j>0 && j < max){
          computerSeq(count);
         
        }else if (j===2){
          j=0;
        } else {
          
          setTimeout(cont, 900);
          j++;
        }
      }; //very important otherwise computer turn will start before end of users's turn
      cont();
    
    } else if (uSeq.length >= cSeq.length && arraysEqual(cSeq, uSeq) === false) {
            var j = 0; var max = 2;
      var cont = function(){
        if (j>0 && j < max){
          computerSeq(count);
         
        }else if (j===2){
          j=0;
        } else {
          
          setTimeout(cont, 900);
          j++;
        }
      }; //very important otherwise computer turn will start before end of users's turn
      cont();
        console.log("wrong");
      
      } 
  }); 
  
 
  
});

            
          
!
999px

Console