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

              
                <link href="https://fonts.googleapis.com/css?family=Poppins" rel="stylesheet">
<div class="container-fluid">     
    <div class="col-md-6 col-md-offset-3 col-sm-6 col-sm-offset-2 col-xs-10" id="appContainer">            
          <div class="row">           
               <div class="col-md-12 col-sm-12 col-xs-12 text-center">
                 <h3 id="title"><b>SIMON SAYS</b></h3>
               </div>           
          </div>          
          
          <div class="row">     
             <div class="col-md-4 col-sm-4 col-xs-0"></div>
                <div id="board" class="col-md-4 col-sm-4 col-xs-12">
                   <div id="bs1" class="boardSpot bs1"></div>
                    <div id="bs2" class="boardSpot bs2"></div>
                      <div id="settings">
                        <div id="roundDisplay">
                           <div class="round">--</div>
                        </div>
                          <div id="settingsButtons">
                              <button id="startBtn" class="btn btn-primary">Go</button>
                              <button type="button" class="btn" id="strictToggle" data-toggle="button" aria-pressed="false" autocomplete="off">Strict off</button> 
                              <div id="powerSwitch">
                                <input id="powerToggle" data-toggle="toggle" type="checkbox" data-size="mini" data-onstyle="primary" data-offstyle="primary" data-on="power on" data-off="power off" />  
                                </div>
                           </div>
                        </div>
                     <div id="bs3" class="boardSpot bs3"></div>
                    <div id="bs4" class="boardSpot bs4"></div>
                 </div>
             <div class="col-md-4 col-sm-4 col-xs-0"></div>
          </div>        
              
    
    </div> <!-- end appContainer -->
  </div> <!-- end container-fluid -->
              
            
!

CSS

              
                @media (max-width: 800px) {
  #appContainer {
    margin-top: 8em;
  }
}
@media (min-width: 768px) and (max-width: 1600px) {
   #appContainer {
    margin-top: 9em;    
   }
}
@media (min-width: 1400px) {
   #appContainer {
    margin-top: 10em;    
   }
}
body {
  font-family: 'Poppins', sans-serif;
}
#title {  
  font-size: 6em;    
}
#board {  
  position:relative;
  width:30em;
  height:30em;    
}
#powerSwitch {
  margin-left: 1.8em;
  margin-top: 1em;
}
#startBtn {
  display:inline-block;
  padding-left: 0.5em;; 
  padding-right: 0.5em; 
}
.boardSpot { 
  height: 10em;;
  width: 10em;  
}
.boardSpot:hover {
  cursor: pointer;
  border:1px solid black;  
}
.bs1 {
  position: absolute;
  left:1em;
  top: 1em;
  background-color: #990000;
  border-top-left-radius: 100%;  
}
.bs1led {
  background-color: red;
}
.bs2 {
  position: absolute;
  left: 11em;
  top: 1em;
  background-color: #cccc00;
  border-top-right-radius : 100%;
}
.bs2led {
  background-color: yellow;
}
.bs3 {
  position: absolute;
  left: 1em;
  top: 11em;
  background-color: #000080;
  border-bottom-left-radius : 100%;
}
.bs3led {
  background-color: #10bcd4;
}
.bs4 {
  position: absolute;
  left:11em;
  top: 11em;
  background-color: green;
  border-bottom-right-radius : 100%; 
}
.bs4led{
  background-color: #00e600;
}
.red {
  background-color: red; 
}
#settings {
  border: 0.2em solid #fff;
  background: #fff;
  border-radius: 50%;
  position: relative;
  z-index: 5;
  top: 6em;
  left: 5em;
  width: 10em;
  height: 10em;  
}
#roundDisplay {  
  margin-left: 35%;
  margin-top: 5%; 
  margin-bottom: 5%;
}
.round {     
  color: #ffcccc;
  border: 1px solid red;
  max-width: 37px;
  text-align: center;
  font-size: 1.5em;
}
.roundActive {
  color:red;
}
#settingsButtons {
  margin-left: 5px;
}
              
            
!

JS

              
                var simon = {
     endRounds: 10, //2 for debugging, 20 for real
     says: [],
     player1: [],
     power:true,
     stop: false,
     strict: false,  
     reset: function() { 
       $(".round").html("--");
       simon.says = [];
       simon.player1 = [];
     },
     playSound: function(bs) {
        var audio = new Audio(simon.sounds[bs]);
          audio.play();
     },
     sounds: {
        1: "https://s3.amazonaws.com/freecodecamp/simonSound1.mp3",
        2: "https://s3.amazonaws.com/freecodecamp/simonSound2.mp3",
        3: "https://s3.amazonaws.com/freecodecamp/simonSound3.mp3",
        4: "https://s3.amazonaws.com/freecodecamp/simonSound4.mp3",
        5: "https://www.nickmcoyle.com:8080/quote/sound/smb3_no_match.wav",
        6: "https://www.nickmcoyle.com:8080/quote/sound/the_price_is_right_theme.wav"    
     },
     startGame: function() {    
        if(simon.says.length === 0) {
           $(".boardSpot").off("click");
           simon.makeSequence(simon.animateSequence);
        };
     },
     add: function() {
        $(".boardSpot").off("click");
        simon.makeSequence(simon.animateSequence);    
     },
     makeSequence: function() {  
        for(var i = 0; i < 1; i++) {
          simon.says.push(simon.getRandom());   
        };
        //update the round display
        if(simon.says.length < 1) {
          $(".round").html("0" + simon.says.length);
        } else {
          $(".round").html(simon.says.length);
        }
        simon.animateSequence();
      },
      bsClick: function() {
        //if power button is turned on then do stuff
        if(simon.power) {           
          var id = $(this).attr("id");   
          var number = Number(id.substring(2,3));
          simon.playSound(number); 
          //console.log($(this));
          simon.player1.push(number);
          //add led
          $(this).addClass(id+"led"); 
          var that = $(this);
          //remove led
          var remove = function() {    
            that.removeClass(id+"led");
          };
            setTimeout(remove, 400);    
            simon.testSequence();
          };
      },
      testSequence: function() {
          var move = simon.player1.length-1;
          var player1Move = simon.player1[move];
          var simonMove = simon.says[move];
            if(player1Move !== simonMove) {
              simon.wrongMoveAnimation();
              simon.player1 = []; 
                if(simon.strict === true) {
                  simon.reset();
                  simon.startGame();
                  return;
                };
              };
          //if end of sequence, then start the next move
          if(simon.player1.length === simon.says.length) {
             //if reached end of rounds, then player1 wins
              if(simon.player1.length === simon.endRounds) {
                 simon.winGameAnimation();
                 return;       
              };
             $(".boardSpot").off("click");
             simon.player1 = [];  
            //add the next round after 1.5 seconds delay
            setTimeout(function () {simon.add()}, 1500);     
          };
       },
       wrongMoveAnimation: function() {
          //light all the spots and play the mario sound
          simon.playSound(5); 
          for(var i = 1; i<5; i++) {
            var boardSpot = $("#bs"+i);    
            boardSpot.addClass("bs"+i+"led");    
          };
        //remove led
        var remove = function() {    
            for(var i = 1; i<5; i++) {
              var boardSpot = $("#bs"+i);   
              boardSpot.removeClass("bs"+i+"led");
            };           
        };
        setTimeout(remove, 1000);
        },
        winGameAnimation: function() {
        //this function blocks user input, lights all the spots, and plays the win sound
        $(".boardSpot").off("click");
        simon.playSound(6);     
        $("#title").html("YOU WIN!!!");   
       var timer = function() {          
          simon.stop = true;          
       };
       //start the timer for 33 seconds the same length as the sound clip
        setTimeout(timer, 33*1000);
          function blink(selector, speed) {
              $(selector).fadeOut(speed, function(){
                $(this).fadeIn(speed, function(){
                if(!simon.stop) {
                  blink(this);
                }
              });
            });
           }
          blink('#title', 1000);                    
          setTimeout(blink('#bs1', 0), 100);
          setTimeout(blink('#bs2', 250), 400);
          setTimeout(blink('#bs3', 500), 800);
          setTimeout(blink('#bs4', 1000), 1200);          
       
        },  
        getRandom: function() {     
          var items = [1,2,3,4];                
          var random = items[Math.floor(Math.random()*items.length)];
          return ( random );   
        },
        animateSequence: function() { 
          //start with the first boardspot in the simon array
          var i = 1;    
          function animateIt(i) {  
            var animateFunc = function() {  
              var id = simon.says[i-1];  
              simon.playSound(id);       
              //add led    
              var boardSpot = $("#bs"+id);    
              boardSpot.addClass("bs"+id+"led");    
               //remove led
               var remove = function() {    
                 boardSpot.removeClass("bs"+id+"led"); 
               };
               setTimeout(remove, 400);   
               i++;
               if(i<=simon.says.length) {                        
                animateIt(i);      
               } else {
                //if the sequence is finished, then allow the player to click
                 setTimeout(allowClick, 250);
               };                    
             };
             setTimeout(animateFunc, 1500);                          
            };      
           animateIt(i);    
           function allowClick() {
              $(".boardSpot").bind("click", simon.bsClick);
           };
        }
}; //end var simon

        $("#startBtn").on("click", function() { 
            if(simon.power) {
                simon.startGame();
            }; 
        });

        $("#strictToggle").on("click", function() {
           if(simon.strict === false) {
              $(this).addClass("btn-danger").text("Strict on");
              simon.strict = true;    
           } else {
             $(this).removeClass("btn-danger").text("Strict off");
             simon.strict = false;
           }
        });

        $("#powerSwitch").on("click", function() {  
           simon.reset();
              if(simon.power === true) {
                 simon.power = false;   
                 $(".round").removeClass("roundActive");
              } else {
                simon.power = true;
                $(".round").addClass("roundActive");
              }  
        });
        
        $(document).ready( function() {    
            $("#powerToggle").bootstrapToggle('on');
            $(".round").addClass("roundActive");
        });
              
            
!
999px

Console