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

              
                <head>
<!--   <link rel="stylesheet" type="text/css" href="style.css">   -->
</head>
<body>
  <div class="container">
    <div class="jumbotron">
      <div class="circle_container">
        <div class="circle red" id="red"></div>
        <div class="circle blue" id="blue"></div>
        <div class="circle green" id="green"></div>
        <div class="circle yellow" id="yellow"></div>
        <div class="inner_circle circle">
          <div class="row"> 
            <div class="col-md-12 col-sm-12 col-lg-12"><h2 class="title">Simon</h2></div>
          </div> 
          <!--            end of title-->
          <div class="row">
            <div class="col-md-6 col-sm-6 col-lg-6 counter">	           
              <div class="row ">
                <div class="count_box">
                  <span class="count">_ _</span>
                </div>
              </div>
              <div class="row ">
                <span class="button_caption ">COUNT</span>
              </div>
            </div>
            <div class="col-md-3 col-sm-3 col-lg-3 start">
              <div class="row">
                <div class="start_button"></div>
              </div>
              <div class="row">
                <span class="button_caption ">START</span>
              </div>
            </div>
            <div class="col-md-3 col-sm-3 col-lg-3 strict">
              <div class="row">
                <div class="strict_light" ></div>
              </div>
              <div class="row">
                <div class="strict_button" data-strict="off"></div>
              </div>
              <div class="row"><span class="button_caption">STRICT</span></div>
            </div>
          </div>
        </div> 
        <!--          end of inner circle-->
      </div>
    </div>
  </div>
</body>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
              
            
!

CSS

              
                .button_caption{
  font-size:8px;
  font-family:Arial, Helvetica, sans-serif;
  font-weight:bold;
}
.circle_container{
  position:relative;
  margin:0px auto;
  height:500px;
  width:500px;
  padding: 20px;
  border-radius:100%;
  border:2px solid #333;
  background:#333;
}
.circle{
  cursor:pointer;
  height:50%;
  width:50%;
  float:left;  
  border: solid #333;
  -webkit-transition: .2s;
  transition: .2s;
}
.count_box{
  width:60px;
  height:40px;
  border-radius:6px;
  border:1px solid #333;
  background:#32050C;
}
.count{
  font-size:20px;
  display:none;
  color:red;
  height:100%;
  width:80%;
  padding-left: 10px;
  padding-top: 5px;

}
.inner_circle{
  position:absolute;
  top:25%;
  left:25%;
  border-radius:100%;
  border:10px solid #333;
  background:#ECE7EE;
  /*   padding:18x; */
  padding:30px 12px 12px 12px  ;
}
.inner_circle > .row{
  margin:0px auto;
}
.counter, .start, .strict{
  padding:0px;
  text-align:center;
  width:33.5%;
}
.counter .row div, .start .row div, .strict .row div{
  margin-left: auto;
  margin-right: auto;
  display:inline-block;
}
.counter .row:nth-child(2), .start .row:nth-child(2), .strict .row:nth-child(3){
  margin-left: auto;
  margin-right: auto;
  bottom:0px;
  display:inline-block;
}


.inner_circle >.row:nth-child(2){
  display:flex;
}

.start_button{
  margin-top:10px;
  height:30px;
  width:30px;
  border-radius:100%;
  background:red;
  box-shadow:0px 2px 3px #222;
  border:2px solid #444;
  -webkit-transition: .2s;
  transition: .2s;
}

.strict_button{
  height:30px;
  width:30px;
  border-radius:100%;
  background:yellow;
  border:2px solid #444;
  box-shadow:0px 2px 3px #222;
  -webkit-transition: .4s;
  transition: .s;
}
.start_button_focus, .strict_button_focus{
  box-shadow:0px 0px 0px #222;
}


.strict{
  margin-top: -12px;
}
.strict_light{
  height:10px;
  width:10px;
  border-radius:100%;
  background:black;
  border:2px solid black;
}

.title{
  font-weight:900;
  font-size:50px;
}
.red{
  border-radius: 100% 0 0 0;
  background: #9f0f17;
  border-width: 0px 10px 10px 0px;

}
.blue{
  border-radius: 0 100% 0 0;
  background: #094a8f;  
  border-width: 0px 0px 10px 10px;
}
.yellow{
  border-radius: 0 0 100%  0;
  background: #cca707;  
  border-width: 10px 0px 0px 10px;
}

.green{
  border-radius: 0 0  0 100%;
  background:green;
  border-width: 10px 10px 0px 0px;
}

.red_focus {
  background:red;
  box-shadow: 2px 2px 2px 2px black inset;
}
.green_focus {
  background: #00a74a; 
  box-shadow: 2px 2px 2px 2px black inset;
}
.yellow_focus {
  background:yellow;
  box-shadow: 2px 2px 2px 2px black inset;
}
.blue_focus {
  background:blue;
  box-shadow: 2px 2px 2px 2px black inset;
}

.inner_circle >.row:nth-child(3){
  margin:0px auto;
  text-align:center;
}



@media only screen AND (max-width: 582px), only screen AND (max-height: 607px) {
  .inner_circle{
    padding:10px;
  }

  .circle_container {
    height: 400px;
    width: 400px;
  }

  .count {
    font-size: 15px;
    padding-left: 0;
    padding-top: 2px;
  }
  .title {
    font-weight: 900;
    font-size: 42px;
  }
  .count_box {
    width: 50px;
    height: 32px;
  }

  .start_button, .strict_button {
    height: 20px;
    width: 20px;
  }
  .start_button {
    margin-top: 10px;
  }
  .strict_light {
    height: 6px;
    width: 6px;
    border-radius: 100%;
  }
  .strict{
    margin-top: -12px;
  }

}


@media only screen AND (max-width: 440px), only screen AND (max-height: 500px) {

  .container .jumbotron, .container-fluid .jumbotron{
    padding-right: 0px; 
    padding-left: 0px; 
    width:100%;
  }
  .circle_container {
    height: 330px;
    width: 330px;
  }

  .title {
    font-size: 32px;
    margin:5px -5px;
  }
  .count_box {
    width: 40px;
    height: 25px;
  }
  .counter{
    margin-top:5px;
  }

  .start .row {
/*     margin-top: 5px; */
  }
  .strict .row {
    margin-top: 0px;
  }
  .inner_circle >.row:nth-child(2){
    width:110%
    margin-top:-10px;
    margin: 0px 0px;
  }

}
              
            
!

JS

              
                const board = ['red','blue','green','yellow'];
const sound={
  'red':'https://s3.amazonaws.com/freecodecamp/simonSound1.mp3',
  'green':'https://s3.amazonaws.com/freecodecamp/simonSound2.mp3',
  'blue':'https://s3.amazonaws.com/freecodecamp/simonSound3.mp3',
  'yellow':'https://s3.amazonaws.com/freecodecamp/simonSound4.mp3'
}
var timer;
var comp=[];
let counter=0;
var player_due=[];
var player_move =false;
var game_start= false;

function reset(){
  clearInterval( timer);
  counter=0;
  comp=[];
  game_start= false;
  player_move= false;
  show_message('_ _'); 
  $('.strict_light').css('background','black');
  $('.strict_button').data('strict','off') ;
  $('.start').find('.button_caption').text('START');
  $('.red').removeClass('red_focus');
  $('.green').removeClass('green_focus');
  $('.blue').removeClass('blue_focus');
  $('.yellow').removeClass('yellow_focus');

}
function make_sound(color){
  let audioElement = document.createElement('audio');
  audioElement.setAttribute('src', sound[color]);
  audioElement.play();
}

function show_message(msg){
  $('.count').text(msg);
}
function comp_move(){
  timer = setTimeout(function(){ //defocus 
    counter ++;  
    const color = board[Math.floor((Math.random() * 3) + 0)];
    comp.push(color);
    player_due=comp.slice();  
    animate_com(comp);  
    show_message(counter);
  }, 1000);
}
function game_state(color){
  const firstElement = player_due.shift();
  if(firstElement != color){ //wrong move by player
    game_finish();
  }else if(firstElement === color){
    player_move =true;
  }
  if(firstElement === color && player_due.length === 0){
    if(counter === 20){
      show_message("win");
    }else{     
      comp_move();     

    }

  }
}

function animate_com(comp){
  let temp = comp.slice();
  if(temp.length>0){
    const x=temp.shift();
    timer=setTimeout(function(){ //focus 
      make_sound(x);
      $('.'+x).addClass(x+'_focus');
    }, 100);
    timer = setTimeout(function(){ //defocus 
      $('.'+x).removeClass(x+'_focus');
      animate_com(temp); //show another element  
    }, 500);
  }
  player_move=true;
}
function game_finish(){
  clearInterval( timer);
  player_move= false;
  if($('.strict_button').data('strict')==="on"){
    show_message("!!!");
    timer = setTimeout(function(){ //defocus 
      comp=[];
      counter=0;
      comp_move();
    }, 1500);

  }else{
    show_message("!!");
    player_due= comp.slice();    
    timer = setTimeout(function(){ //defocus 
      show_message(counter);
      animate_com(comp);
    }, 1500);

  }
}
$(document).ready(function() {

  $('.start_button').on('touchstart mousedown',function(){
    if( game_start=== false && player_move=== false){
      $('.start').find('.button_caption').text('RESET');
      game_start= true;
      $('.count').css('display','block');
      $('.start_button').addClass('start_button_focus');
      comp_move();
    }else if(game_start){
      reset();
    }
  }).on('touchend mouseup',function(){
    $('.start_button').removeClass('start_button_focus');
  });

  $('.strict_button').on('touchstart mousedown',function(){
    const strict= $(this).data('strict');
    $('.strict_button').addClass('strict_button_focus');
    if (strict==="off"){
      $('.strict_light').css('background','red');
      $(this).data('strict','on');
    } else{
      $('.strict_light').css('background','black');
      $(this).data('strict','off') ;
    } 
    if(game_start){
      reset();
     }

  }).mouseup(function(){
    $('.strict_button').removeClass('strict_button_focus');
  });

  $("#red,#green,#yellow,#blue").on('touchstart mousedown',function(){
    if(game_start && player_move){
      const id=  $(this).attr('id');
      make_sound(id);
      $('.'+id).addClass(id+'_focus');
    }
  }).on('touchend mouseup',function(){
    const id=  $(this).attr('id');
    $('.'+id).removeClass(id+'_focus');
    game_state(id);
  });


});
              
            
!
999px

Console