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

              
                
      <h1 class="text-center" style="margin-top:3%">Simon Says Game</h1>
  
<!--Modaal-->
<div class = "row">
  <div class="text-center" style="margin-top:3%;margin-bottom:3%;">
<h2 class="text-center">Hi! Please Follow the <button type="button" class="btn btn-success btn-lg" data-toggle="modal" data-target="#mymodal">Rules</button>Before Playing!. . .Good Luck!</h2>
  </div>
</div>
<div id="mymodal" class="modal fade" role="dialog">
  <div class = "modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Rules</h4>
      </div>
      <div class="modal-body">
       <ol class="text-center">
           <li> You can play either strict or simple by pressing (start button)</li>
           <li> After loosing refresh the page to play again.</li>
           <li> Just select the current highlighted button when playing in start mode.</li>
           <li> There are 16 levels for start button. </li>
           <li> Enjoy. </li>
      </ol> 
      </div>
      <div class="modal-footer">
        <button class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
  </div>
</div>
</div>
<!---->


<div class = "container">
  
  
  
  <div class = "game-container">
    <div class = "row">
      <div class="col-md-12 col-xs-12">
    <div id="green-btn" class="game-buttons "></div>
    <div id="red-btn" class="game-buttons"></div>
    <div id="yellow-btn" class="game-buttons"></div>
    <div id="blue-btn" class="game-buttons"></div>
  
  
  
  <div class="game-panel">
  <div class="title">Simon</div>
  <div id="countBox"><span class="count"></span></div>
  <div id="startbtn"><span class="start">Start</span></div>
  <div id="strictbtn"><span class="start">Strict</span></div>
  <div id="on-off-btn">
    <div id="on-off-switch">
     <div id="on-off-switch1">
  </div>
    </div>
  </div>
  
  <div class="toggle">
    </div>
    <div class="toggle1">
    </div>
    
    <span class="on-text">Off</span>
    <span class="off-text">On</span>
    
    
        </div>
    </div>
  </div>
    
 </div>
</div>
<div class = "footer nav navbar-bottom navbar-inverse">
  <h5 style="color:white;" class="text-center">Coded and designed By Mohammad Hasham with &hearts;</h5>
  <h5 style="color:white;" class="text-center">Copyrights © 2016-2017</h5>
</div>




              
            
!

CSS

              
                body{
   background-color:#1DE9B6;
}
.container{
  width:700px;
}
h1{
  font-family:'Open Sans', sans-serif;
}
.game-container{
  width:600px;
}
.game-buttons{
  float:left;
  border: 8px solid #1D1F20;
  width:290px;
  height:290px;
  
}
#green-btn{
   background-color:#0a0;
    border-radius: 300px 0 0 0;
    border-top: 20px solid #1D1F20;
    border-left: 20px solid #1D1F20;
}
#red-btn{
   background-color:#a00;
    border-radius: 0px 300px 0 0;
    border-top: 20px solid #1D1F20;
    border-left: 20px solid #1D1F20;
    border-right: 20px solid #1D1F20;
}
#yellow-btn{
   background-color:#aa0;
    border-radius: 0px 0px 0 300px;
    border-top: 20px solid #1D1F20;
    border-left: 20px solid #1D1F20;
   
}
#blue-btn{
    background-color:#00a;
    border-radius: 0px 0px 300px 0px;
    border-top: 20px solid #1D1F20;
    border-left: 20px solid #1D1F20;
    border-right: 20px solid #1D1F20;
}
.game-panel{
  width:245px;
  height:245px;
  position:relative;
  z-index:10;
  border-radius:150px;
  border:15px solid #1D1F20;
  background-color:white;
  top: 175px;
  left: 168px;
}
.title{
  top:20px;
  left: 15px;
  font-family: 'Righteous', cursive;
  font-weight: bold;
  padding-left: 26px;
  font-size: 3.5em;
  position:absolute;
}
#countBox{
  height: 45px;
  width: 60px;
  border-radius: 6px;
  background-color: #1D1F20;
  top: 90px;
  left:20px;
  font-size: 2.3em;
  position:absolute;
}
.start{
  top:27px;
  position:absolute;
  left:-3;
}
#startbtn{
  height: 35px;
  width: 35px;
  border-radius: 100px;
  border: 5px solid #1D1F20;
  background-color: #F72023;
  top: 95px;
  left: 105px;
  position:absolute;
}
#strictbtn{
  height: 35px;
  width: 35px;
  border-radius: 100px;
  border: 5px solid #1D1F20;
  background-color: #F9FC3F;
  top: 95px;
  left: 160px;
  position:absolute;
}
#on-off-btn{
  width:80px;
  height:35px;
  background-color:#1D1F20;
  top:153px;
  left:70px;
  position:absolute;
}
#on-off-switch{
  height: 27px;
  width: 30px;
  margin: 4px;
  background-color: #BEC9CE;
  position: relative !important;
  z-index:40;
}
#on-off-switch1{
  height: 27px;
  width: 30px;
  margin-left:41px;
  background-color: #BEC9CE;
  position: relative !important;
  z-index:40;
}
.on-text{
  left: 45px;
  top: 160px;
  position:absolute;
}
.off-text{
  left: 155px;
  top: 160px;
  position:absolute;
}
.toggle{
  left:40px;
}
.toggle1{
 background-color: black !important;
}


/**Highlighting Effects**/
.yellowClass{
 /* background-color:#aa0;
  opacity:0.5;*/
  background-color:black;
}
.yellowNewClass{
  background-color:#aa0;
  opacity:1;
  background-color:black;
}
.greenClass{
  /*background-color:#0a0;
  opacity:0.5;*/
  background-color:black;
}
.greenNewClass{
  background-color:#0a0;
  opacity:1;
  background-color:black;
}
.redClass{
  /*background-color:#a00;
  opacity:0.5;*/
  background-color:black;
}
.redNewClass{
  background-color:#a00;
  opacity:1;
  
}
.blueClass{
  /*background-color:#00a;
  opacity:0.5;*/
  background-color:black;
}
.blueNewClass{
  background-color:#00a;
  opacity:1;
 
}
.footer{
  width:1380px;
  height:70px;
  margin-top:1%;
}


              
            
!

JS

              
                $(document).ready(function() {
  var counter = 0;
  var arr = []; /**Array to store the highlighted elements**/
  var arr1 = []; /**Array to store user input**/
  var arr2 = [];
  var correctInput = 0; /**Number of correct inputs to match with highlighted instances.**/
  var userCounter = 0;
  var start = 0; /**Start counter**/
  var i = 0;
  var value = 0;
  var cage = 0;
  var caught = 0;
  var ft = 0;
  
  var audio1 = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3');
  var audio2 = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound2.mp3');
  var audio3 = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound3.mp3');
  var audio4 = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound4.mp3');

  $('#on-off-switch1').hide();
  var flag = 0; /** Switch Button flag*/
  /** Switch Button Logic Start**/
  $('#on-off-btn').click(function() {
    if (flag === 0) {
      $('#on-off-switch').css('margin-left', '42px');
      flag = 1;
    } else if (flag == 1) {
      $('#on-off-switch').css('margin-left', '4px');
      flag = 0;
    }
  });
  /** Switch Button Logic End**/

  $('#strictbtn').click(function() {
    var j = 0;
    /**Checking If The Switch Is Already On**/
    if (flag == 1) {
      counter++; /**Just to call function to be called number of times.**/
      callColor(counter); /**Highlights the color patters**/
      //console.log(arr);
    } else {
      // Do Nothing
    }
  });
  $('#startbtn').click(function() {
    if (flag == 1) {
      start = 1;
      simpleGame();
    } else {
      //Do Nothing
    }
  });

  function simpleGame() {
    value++;
    console.log(value);
    if (value == 1 || value == 6 || value == 11) {
      $('#yellow-btn').fadeOut(100);
      $('#yellow-btn').fadeIn(300);
      audio1.play();
      arr2[0] = 'yellow';
      var ft = value;
      finalFunc();
    } else if (value == 2 || value == 7 || value == 12) {
      $('#yellow-btn').fadeOut(100);
      $('#yellow-btn').fadeIn(300);
      arr2[0] = 'yellow';
      audio2.play();
      $('#green-btn').fadeOut(1000);
      $('#green-btn').fadeIn(300);
      arr2[1] = 'green';
      var ft = value;
      finalFunc();
    } else if (value == 3 || value == 8 || value == 13) {
      $('#yellow-btn').fadeOut(100);
      $('#yellow-btn').fadeIn(300);
      arr2[0] = 'yellow';

      $('#green-btn').fadeOut(1000);
      $('#green-btn').fadeIn(300);
      arr2[1] = 'green';

      $('#red-btn').fadeOut(3000);
      $('#red-btn').fadeIn(300);
      arr2[2] = 'red';
      var ft = value;
      finalFunc();
      audio3.play();
    } else if (value == 4 || value == 9 || value == 14) {
      $('#yellow-btn').fadeOut(100);
      $('#yellow-btn').fadeIn(300);
      arr2[0] = 'yellow';

      $('#green-btn').fadeOut(1000);
      $('#green-btn').fadeIn(300);
      arr2[1] = 'green';

      $('#red-btn').fadeOut(3000);
      $('#red-btn').fadeIn(300);
      arr2[2] = 'red';
      var ft = value;
      finalFunc();
    } else if (value == 5 || value == 10 || value == 15) {
      $('#yellow-btn').fadeOut(100);
      $('#yellow-btn').fadeIn(300);
      arr2[0] = 'yellow';

      $('#green-btn').fadeOut(1000);
      $('#green-btn').fadeIn(300);
      arr2[1] = 'green';

      $('#red-btn').fadeOut(3000);
      $('#red-btn').fadeIn(300);
      arr2[2] = 'red';

      $('#blue-btn').fadeOut(5000);
      $('#blue-btn').fadeIn(300);
      arr2[3] = 'blue';
      var ft = value;
      finalFunc();
    }
  }

  function finalFunc() {

    $('#yellow-btn').click(function() {
      audio1.play();
      if (arr2[0] === 'yellow') {
        compareStart();
      }
    });

    $('#green-btn').click(function() {
      audio2.play();
      if (arr2[1] === 'green') {
        compareStart();
      }
    });

    $('#red-btn').click(function() {
      audio3.play();
      if (arr2[2] === 'red') {
        compareStart();
      }
    });

    $('#blue-btn').click(function() {
      audio4.play();
      if (arr2[3] === 'blue') {
        compareStart();
      }
    });
  }

  /** User Inputs Check Start**/
  $('#green-btn').click(function() {
    arr1.unshift(2);
    userCounter++;
    audio1.play();
    if (counter !== 0) {
      compareArrays();
    }
  });
  $('#yellow-btn').click(function() {
    arr1.unshift(1);
    userCounter++;
    audio2.play();
    if (counter !== 0) {
      compareArrays();
    }
  });
  $('#red-btn').click(function() {
    arr1.unshift(3);
    userCounter++;
    audio3.play();
    if (counter !== 0) {
      compareArrays();
    }
  });
  $('#blue-btn').click(function() {
    arr1.unshift(4);
    userCounter++;
    audio4.play();
    if (counter !== 0) {
      compareArrays();
    }
  });
  /** User Inputs Check End**/

  /** Computer Generation of colors start**/
  function callColor(counter) {
    var value = counter;
    while (value !== 0) {

      var x = Math.floor((Math.random() * 4) + 1); /**Any number generated between 1 to 4**/

      if (x == 1) {
        //yellow
        $('#yellow-btn').fadeOut(100);
        $('#yellow-btn').fadeIn(300);
        audio1.play();
        //yellow
        arr.unshift(x);

      } else if (x == 2) {
        //green
        $('#green-btn').fadeOut(500);
        $('#green-btn').fadeIn(300);
        audio2.play();
        //green
        arr.unshift(x); // arr[1] = x;

      } else if (x == 3) {
        $('#red-btn').fadeOut(2000);
        $('#red-btn').fadeIn(300);
        audio3.play();
        //green
        arr.unshift(x); // arr[1] = x;

      } else if (x == 4) {
        //blue
        $('#blue-btn').fadeOut(200);
        $('#blue-btn').fadeIn(300);
        //blue
        audio4.play();
        arr.unshift(x); //arr[3] = x;

      }

      value--;
      // console.log(arr);

    }
  }
  /**arrays comparison**/
  function compareArrays() {
    var flag = 0;

    if (userCounter == counter) /**Check if user has completed his action**/ {
      for (var i = 0; i < counter; i++) {
        flag++;
        if (arr[i] !== arr1[i]) {
          alert('You Loose!');
          flag--;
          //  console.log(arr + " " +arr1);
        }
      }

      if (flag == counter) {
        displayCounter(counter);
      }
    }
  }

  function compareStart() {

    caught++;
    if (arr2[0] !== 'yellow' && arr2[3] !== 'blue' && arr2[2] !== 'red' && arr2[1] !== 'green') {
      alert('You Loose!');
    } else if (caught === value) {
      displayCounter(value);
    }

  }
  /****/
  /** Computer Generation Of Colors End**/
  function displayCounter(counter) {
    if (start !== 0) {
      $('#countBox').text(value).css('color', 'red');
      if (value == 15)
        {
          alert('You Won!');
        }
      userCounter = 0;
      for (var i = 0; i < start; i++) {
        arr[i] = ',';
        arr1[i] = ',';
        arr2[i] = ',';
      }
      i = 0;
      caught = 0;
      $('#startbtn').trigger('click');
    } else if (counter !== 0) {
      $('#countBox').text(counter).css('color', 'red');
      for (var i = 0; i < counter; i++) {
        arr[i] = ',';
        arr1[i] = ',';

      }
       if (counter == 15)
        {
          alert('You Won!');
        }
      console.log(arr + ' ' + arr1);
      userCounter = 0;
      $('#strictbtn').trigger('click');
    }
  }
});
              
            
!
999px

Console