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 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

              
                <body>
  <div class='simonCont'>
    <div class='toprow'>
      <div id='ul' class='circleButton ul blue'>
      </div>
      <div id='ur' class='circleButton ur green'>
      </div>
    </div>
    <div class='center'>
      <p id='simon'>Simon<span id='copyright'>®</span></p>
      <div id='controls'>
          <p id='countertext'>00</p>
          <p id='countlabel'>COUNT</p>
        <div id='startbutton'>
        </div>
        <div id='starttext'>START</div>
        <div id='strictindicate'></div>
        <div id='strictbutton'></div>
        <p id='stricttext'>STRICT</div>
      <br>
      <label class="switch">
        <p id='on'>ON</p>
        <input type="checkbox">
          <span class="slider"></span>
        
            <p id='off'>OFF</p>
        </label>
      </div>
      
    </div>
      <div id='ll' class='circleButton ll red'>
      </div>
      <div id='lr' class='circleButton lr yellow'>
      </div>
  </div>
    
  </div>
</body>
              
            
!

CSS

              
                body{
  background-image: url(https://burst.shopifycdn.com/photos/wooden-table-texture_925x.jpg);
  background-size: cover;
  background-repeat: no repeat;
  font-size: 14pt;
}
.toprow{
  position:relative;
  margin-bottom: 50vh;
  height:50vh;
}

.center{
  position:absolute;
  width:40vw;
  max-width:40vh;
  height:40vw;
  max-height:40vh;
  border-radius:50%;
  border-color: black;
  border-width: 10px;
  border-style: solid;
  background-color: grey;
  left:0;
  right:0;
  top:0;
  bottom:0;
  margin: auto;
  text-align: center;
  padding:15px;
  z-index:10;
}
#copyright{
  font-size:4vh;
}

#countertext{
  position:absolute;
  font-family: 'Press Start 2P', sans-serif;
  font-size:1.3vw;
  color:red;
  background:black;
  border-radius:20%;
  width:3vw;
  min-width: 25px;
  max-width:40px;
  height: 5vh;
  padding:3px;
  padding-top:3%;
  top:42%;
  left:8%;
}

#countlabel{
  position:absolute;
  font-size:8pt;
  top:62%;
  left:9%;
}
#startbutton{
  position:absolute;
  top:42%;
  left:44%;
  background-color:red;
  height:2vw;
  min-height:20px;
  width:2vw;
  min-width:20px;
  border-radius:50%;
  box-shadow: 4px 4px 3px #222;
}
#startbutton:active{
  box-shadow: 2px 2px 2px #222;
  
}
#starttext{
  position:absolute;
  font-size:8pt;
  top:62%;
  left:41%;
}
#strictindicate{
  position:absolute;
  height:5px;
  width:5px;
  background-color:black;
  border-radius:50%;
  border-width:1px;
  border-color:black;
  border-style:solid;
  top:44%;
  left:70%
    
}
#strictbutton{
  position:absolute;
  background-color:yellow;
  height:2vw;
  min-height:20px;
  width:2vw;
  min-width:20px;
  border-radius:50%;
  top:42%;
  left:75%;
  box-shadow: 4px 4px 3px #222;
}
#strictbutton:active{
  box-shadow: 2px 2px #222;
}
#stricttext{
  position:absolute;
  font-size:8pt;
  top:62%;
  left:70%; 
}
#on{
  position:absolute;
  font-size:8pt;
  top:15%;
  right:110%;
}

#off{
  position:absolute;
  font-size:8pt;
  top:15%;
  left:110%;
}

.switch {
  position: absolute;
  display: inline-block;
  width: 35px;
  height: 20px;
  top:75%;
  left:35%;
}

/* Hide default HTML checkbox */
.switch input {display:none;}

/* The slider */
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #222;
  -webkit-transition: .4s;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 12px;
  width: 15px;
  left: 4px;
  bottom: 4px;
  background-color: grey;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .slider {
}

input:focus + .slider {
  box-shadow: 0 0 1px #2196F3;
}

input:checked + .slider:before {
  -webkit-transform: translateX(14px);
  -ms-transform: translateX(14px);
  transform: translateX(14px);
}
@media (max-width:900px){
  #countertext{
    font-size:7pt;
    max-height:3vh;
  }
}
@media (min-width:1440px){
  #countertext{
    font-size:2vh;
    max-height:5vh;
  }
}

@media (max-width:420px){
  #on{
    font-size:5pt;
    top:25%;  
  }
  #off{
    font-size:5pt;
    top:25%;   
  }
  #countertext{
    font-size:7pt;
    max-height:20px;
  }
  #strictindicate{
    left:68%;
  }
  #countlabel{
    font-size:5pt;    
  }
  #stricttext{
    font-size:5pt;    
  }
  #starttext {
    font-size:5pt;
    left:40%;
  }
}
#simon{
  font-size:7vh;
  margin-top:8%;
  font-family: 'Vollkorn SC', serif;
}
@media (max-width:600px){
  #simon{
    margin-top:1.4%;
    font-size:7vw;
  }
  #copyright{
  font-size:3vw;
  }
}
.ul{
  background-color:blue;
  position:absolute;
  width:40vw;
  max-width:40vh;
  height:40vw;
  max-height:40vh;
  margin-right: 50%;
  bottom:0;
  right:0;
  border-top-left-radius: 100%;
  border-color: black;
  border-width: 12px;
  border-style: solid;
}

.ul:active{
  background-color:cyan;
}
.ur{
  background-color:green;
  position:absolute;
  width:40vw;
  max-width:40vh;
  height:40vw;
  max-height:40vh;
  margin-left: 50%;
  bottom:0;
  left:0;
  border-top-right-radius: 100%;
  border-color: black;
  border-width: 12px;
  border-style: solid;
  box-shadow: 10px 10px 7px #222;
}
.ur:active{
  background-color:chartreuse;
}
.ll{
  background-color:red;
  position:absolute;
  width:40vw;
  max-width:40vh;
  height:40vw;
  max-height:40vh;
  margin-right: 50%;
  top:50vh;
  right:0;
  border-bottom-left-radius: 100%;
  border-color: black;
  border-width: 12px;
  border-style: solid;
  box-shadow: 10px 10px 7px #222;
}

.ll:active{
  background-color: tomato;
}
.lr{
  background-color:gold; 
  position:absolute;
  width:40vw;
  max-width:40vh;
  height:40vw;
  max-height:40vh;
  margin-left: 50%;
  top:50vh;
  left:0;
  right:0;
  border-bottom-right-radius: 100%;
  border-color: black;
  border-width: 12px;
  border-style: solid;
  box-shadow: 10px 10px 7px #222;
}
.lr:active{
  background-color:yellow;

  
}
              
            
!

JS

              
                /* 

***TO DO***



*/


//SETUP

var gamestate = [];
var gamerunning = false;
var onOff = true;
var tempo = 4000;
var isStrict = false;
var playerTurn = false;
//variables used to check player choices
var playerChoices=[];
var choiceCounter=0;
var winval=20;
var buttons={
  'ul':
  {   
    'col1': 'blue',
    'col2': 'cyan',
    'sound': new Audio('https://s3.amazonaws.com/freecodecamp/simonSound2.mp3')
 },
  'ur': 
  {
    'col1': 'green',
    'col2': 'chartreuse',
    'sound': new Audio('https://s3.amazonaws.com/freecodecamp/simonSound3.mp3')
},
  'll':{
    'col1': 'red',
    'col2': 'firebrick',
    'sound': new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3')
  },
  'lr': {
    'col1': 'gold',
    'col2': 'yellow',
    'sound': new Audio('https://s3.amazonaws.com/freecodecamp/simonSound4.mp3')
  }
};

function gameover(){
  gamestate=[];
  playerTurn=false;
  playerChoices=[];
  choiceCounter=0;
  tempo=2500
}

//On/off switch functionlity
function switchListener(callback){
  //turning off
  if(onOff===true){
    gameover();
    $('#ul').css('background-color', buttons.ul.col1)
    $('#ur').css('background-color', buttons.ur.col1)
    $('#ll').css('background-color', buttons.ll.col1)
    $('#lr').css('background-color', buttons.lr.col1)
    $('#countertext').css('color', 'black');
    $('#countertext').innerHTML=
    isStrict=false;
    $('#strictindicate').css('background-color', 'black');
    gamerunning=false;
    if(gamestate.length<10){
      $('#countertext')[0].innerHTML='0'+gamestate.length; 
    } 
    else{
      $('#countertext')[0].innerHTML=gamestate.length;
    }
    //gameover();
    //game reset and clear all timeouts/intervals
  }
  //turning on
  console.log('currently: '+onOff );
  if(onOff===false){
    console.log('turning on');
    isStrict=false;
    $('#countertext').css('color', 'red');
  }
  callback();
}
function switchCallback(){
  console.log('callback is firing');
  if(onOff===true){onOff=false;console.log(onOff);} else if(onOff===false){onOff=true;console.log(onOff);}
}
//event listener for on/off switch
$('.switch').mouseup(function(){switchListener(switchCallback);});
//listener for the start button 
$('#startbutton').mouseup(function(){
  if(onOff===true&&gamerunning===false){
    gamerunning=true;
    console.log('time for the cpu turn to start');
    // functionality to reset game in progress.
    cpuTurn(cpuRecite('the start button'));
  }
});
//listener on the strict button
$('#strictbutton').mouseup(function (){
  if(isStrict===true){
    isStrict=false;
    $('#strictindicate').css('background-color', 'black');
    console.log('you turned strict mode off');
  }
  else if(isStrict===false){
    isStrict=true;
    $('#strictindicate').css('background-color', 'blue');
    console.log('you turned strict mode on');  
  }
});

// *** PLAYER TURN & button press functions ***
$('.circleButton').mousedown(function(event){
  event.stopPropagation();
  if(onOff===true){
    var thisbut=event.currentTarget.id;
    //console.log('you have chosen: '+thisbut);
    buttons[thisbut].sound.play();
    
      $('#'+thisbut).css('background-color', buttons[thisbut].col2);
      setTimeout(function(){
      //  console.log(this);
       $('#'+thisbut).css('background-color', buttons[thisbut].col1);
      }, tempo/2);
    //play 
    
    if(playerTurn===true){
      playerChoices.push(this.id);
      //if wrong
      if(playerChoices[choiceCounter]!==gamestate[choiceCounter]){
        console.log('choice #: '+choiceCounter);
        console.log(gamestate);
        console.log('the right choice was:'+ gamestate[choiceCounter]);
        console.log('you picked: '+playerChoices[choiceCounter]);
        console.log('you flubbed it!!');
        $('#ul').css('background-color', buttons.ul.col2);
        $('#ur').css('background-color', buttons.ur.col2);
        $('#ll').css('background-color', buttons.ll.col2);
        $('#lr').css('background-color', buttons.lr.col2);
        $('#countertext')[0].innerHTML='--';
        buttons.ul.sound.play();
        buttons.ll.sound.play();
        buttons.ur.sound.play();
        buttons.lr.sound.play();
        if(isStrict===true){
          setTimeout(function(){
          $('#countertext')[0].innerHTML='01';
          $('#ul').css('background-color', buttons.ul.col1);
          $('#ur').css('background-color', buttons.ur.col1);
          $('#ll').css('background-color', buttons.ll.col1);
          $('#lr').css('background-color', buttons.lr.col1);
          }, 150);
          //game over
          gameover();
          choiceCounter=0;
          cpuTurn();
        }
        else{
          setTimeout(function(){
            if(gamestate.length<10){
              $('#countertext')[0].innerHTML='0'+gamestate.length; 
            } 
            else{
              $('#countertext')[0].innerHTML=gamestate.length;
            }
          $('#ul').css('background-color', buttons.ul.col1);
          $('#ur').css('background-color', buttons.ur.col1);
          $('#ll').css('background-color', buttons.ll.col1);
          $('#lr').css('background-color', buttons.lr.col1);
          }, 150);
          choiceCounter=0;
          console.log('resetting cpu recite');
          setTimeout(function(){
            playerTurn=false                            
          cpuRecite('a non-strict game over');}, tempo);
          
        }
      } else {
        console.log('success!');
        choiceCounter++;
        console.log('now match choice #'+choiceCounter)
        if (choiceCounter==gamestate.length){
          cpuTurn();
          choiceCounter=0;
        }
      }
      
    }
  }
});



// ***CPU AI functionality**&
function cpuTurn(){
  var cpuChoices=['ul', 'ur', 'll', 'lr'];
  var nextChoice=cpuChoices[Math.floor(Math.random()*cpuChoices.length)];
  
  gamestate.push(nextChoice);
  if (gamestate.length===winval){
    console.log('you win!')
    gameover();
    $('#ul').css('background-color', buttons.ul.col2)
    $('#ur').css('background-color', buttons.ur.col2)
    $('#ll').css('background-color', buttons.ll.col2)
    $('#lr').css('background-color', buttons.lr.col2)
    $('#countertext').css('color', 'black');
    buttons.ul.sound.play();
    setTimeout(function(){
          $('#countertext').css('color', 'red');
          $('#countertext').innerHTML=gamestate.length;
          $('#ul').css('background-color', buttons.ul.col1);
          $('#ur').css('background-color', buttons.ur.col1);
          $('#ll').css('background-color', buttons.ll.col1);
          $('#lr').css('background-color', buttons.lr.col1);
          cpuTurn();
          }, 150);
    
  }
  else{
    if (gamestate.length===5||gamestate.length===9||gamestate.length===13){
      tempo=0.5*tempo;}
    if(gamestate.length<10){
      $('#countertext')[0].innerHTML='0'+gamestate.length; 
    } 
    else{
      $('#countertext')[0].innerHTML=gamestate.length;
    }
    console.log('the next choice is: '+nextChoice+' the choices so far are: '+gamestate);
    cpuRecite('the end of cputurn();');
  }
}

  function cpuRecite(runfrom){
  console.log('cpuRecite is bring run '+runfrom)
  //iterate gamestate array, each time playing a sound and changing colors
  var currentCount=0;
  var reciteTime=setInterval(function(){
    if(currentCount===gamestate.length-1){
        playerTurn=true;
    }
    if(currentCount===gamestate.length){
      if(onOff===true){
        
        clearInterval(reciteTime);
        playerChoices=[];
        console.log('choiceCounter would be reset by cpurecite, but you are wearing the clever pants');
        
      }
    }
    else{
      if (onOff===true&& gamestate.length>0){
        console.log(buttons[gamestate[currentCount]]);
        $('#'+gamestate[currentCount]).css('background-color', buttons[gamestate[currentCount]].col2);
        //console.log('logging button object from the DOM...');
        //console.log($('#'+gamestate[currentCount]));
        //console.log('changing color of: '+ [gamestate[currentCount]]+ ' to: '+buttons[gamestate[currentCount]].col2);
        buttons[gamestate[currentCount]].sound.play();
        setTimeout(function(){
          $('#'+gamestate[currentCount]).css('background-color', buttons[gamestate[currentCount]].col1);
          //console.log('changing color of: '+ [gamestate[currentCount]]+ ' to: '+buttons[gamestate[currentCount]].col1);
          currentCount++;
        }, (tempo/2));
      }
    }
  },tempo);
}
              
            
!
999px

Console