cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm 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. We'll also process your JavaScript with Babel.

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

Code Indentation

     

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.

            
              <link href="https://fonts.googleapis.com/css?family=Press+Start+2P" rel="stylesheet" type="text/css">
<audio id = "greenAudio">
  <source src = "http://www.quizmasters.biz/DB/Audio/Whats%20That%20Noise/Mp3/Chewbacca_01.mp3"
          type = "audio/mp3">
</audio>

<audio id = "redAudio">
  <source src = "http://www.quizmasters.biz/DB/Audio/Whats%20That%20Noise/Mp3/Light%20Saber_Open.mp3"
          type = "audio/mp3">
  
</audio>

<audio id = "yellowAudio">
  <source src = "http://www.quizmasters.biz/DB/Audio/Whats%20That%20Noise/Mp3/Star%20Wars%20Speed%20Bike_01.mp3"
          type = "audio/mp3">
</audio>

<audio id = "blueAudio">
  <source src = "http://www.quizmasters.biz/DB/Audio/Whats%20That%20Noise/Mp3/R2D2_01.mp3"
          
          type = "audio/mp3">
</audio>

<div class = "container">

  <h2 id = "header">Star Wars Simon Game</h2>
  <p id = "fcc">FreeCodeCamp</p>
  <div id = "gameButtons">
    
<div class = "col align-self-center">
<div class = "row">
<button class = "btn" id = "green">Green</button>
<button class = "btn" id = "red">Red</button>
</div>
</div>

<div class = "col align-self-center">    
<div class = "row">
  <button class = "btn" id = "yellow">Yellow</button>
  <button class = "btn" id = "blue">Blue</blue>
</div>
    </div>  
  
  </div> <!-- ends buttons container-->
    
<div class = "row" id = levelRow>
<p id = 'level'>Level</p>
<p id = "turns">No. of turns</p>
</div>
<p id = "attempt">Let's do this!</p>
<div class = "row" id = "toggleRow">
  <p id = "strictMode">Strict Mode:</p>
<p id = "toggle">Off</p>  
</div>  

<div class = "row" id = "audioRow">
  <p id = "audioHeader">Audio:</p>
  <p id = "audio">On</p>
</div>

<button class = "btn btn-primary" id = "strict">Strict/Easy</button>
<button class ="btn btn-danger" id = "reset">Reset</button>
<button class = "btn btn-warning" id = "mute">Mute</button>
  
</div><!-- ends div container-->
            
          
!
            
              body{
  background-image: url("https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/12797578_185520361837371_2000169294_n.jpg?ig_cache_key=MTIxMDUxMjU4NTI5MzIxMTgwMw%3D%3D.2");
  background-attachment: fixed;
  color: white;
  font-family: "Press Start 2P";
  text-align: center;
}
.container{
width: 50%;}

#gameButtons{margin-left: 35%;}

.btn{height: 100px;
width: 100px;
margin: 1px;}

#green{background-color: rgb(132,178,142)}

#red{background-color: rgb(198,97,97);}

#yellow{background-color: rgb(195,198,97);}

#blue{background-color: rgb(128,161,214);}

#levelRow, #audioRow{margin-left: 40%;}
#toggleRow {margin-left: 32%;}
#attempt {margin-left:20px;}

#turns, #toggle, #audio{margin-left:5px;}

#reset, #mute{height: 50px;
width: 75px;}

#strict{height: 50px;
width: 100px;
padding: 5px;}

.row{text-align: center;}
            
          
!
            
              $(document).ready(function(){

  var master = [];
  var attempt = [];
  
  var delay = 1000;
  var playersTurn = 1;
  var clicks = 0;
  var toggle = 0;
  var mute = 0;
  
function playGreen(){
  var g = document.getElementById("greenAudio");
  g.play();
};
  
  function playRed(){
  var r = document.getElementById("redAudio");
  r.play();
};
  
  function playYellow(){
  var y = document.getElementById("yellowAudio");
  y.play();
};
  
function playBlue(){
  var b = document.getElementById("blueAudio");
  b.play();
};
  
  function green (){  
  $("#green").css("background-color", "rgb(33,237,26)");
  setTimeout(function(){ $("#green").css("background-color", "rgb(132,178,142)"); },delay);
    if(mute==1){}else{playGreen();};
  };
  
  function red(){
    $("#red").css("background-color", "rgb(249,4,9)");
  setTimeout(function(){ $("#red").css("background-color", "rgb(198,97,97)"); },delay);
        if(mute==1){}else{playRed();};
  };
  
  function yellow(){
    $("#yellow").css("background-color", "rgb(241,249,4)");
  setTimeout(function(){ $("#yellow").css("background-color", "rgb(195,198,97)"); },delay);
        if(mute==1){}else{playYellow();};
  };
  
  function blue(){
    $("#blue").css("background-color", "rgb(25,4,249)");
  setTimeout(function(){ $("#blue").css("background-color", "rgb(128,161,214)"); },delay);
        if(mute==1){}else{playBlue();};
  };
  
  //random number generator to put on extra step
   function addNewEntry(){
    var rand = Math.random();

     
    switch(true){
    
      case (rand<0.25):
        master.push(green);
        break;
        
      case (rand<0.5):
        master.push(red);
        break;
        
      case (rand<0.75):
        master.push(yellow);
        break;
        
      case (rand<1):
        master.push(blue);
        break;
               }
      $("#turns").html(master.length);
  };
  
  //computers go to show pattern
  function compGo(){
     var call = '';
  (function theLoop(i){
    setTimeout(function(){
      call = master[i];
      console.log(master);
      call();
      if(i++<(master.length)){
        theLoop(i);
         }},delay+500);
    })(0);
 };  //ends recall of pattern designed by comp
  
  addNewEntry();

  //code that handles what happens if you get click right
  //if clicks = end => new entry
  //else add on new click and wait for user input
  function successProcess(){
 
   if(clicks==(master.length-1)){
      if(master.length==20){
        $("#attempt").html("Winner, winner, chicken dinner!");}
      else{
       attempt = [];
       clicks = 0;       
       addNewEntry();       
       compGo();}}
  else{clicks++};
  };
  
  //reset function
  function reset(){
  
    clicks = 0;
    $("#turns").html(clicks);
    attempt = [];
    master = [];
    $("#attempt").html("Let's do this!");
    $("#attempt").css("color", "white");
    addNewEntry();
    compGo();
  };
  
  //reset button
  $("#reset").click(reset);
  
  //strict mode toggle button - used to reset on error if on.
  $("#strict").click(function(){
    if(toggle==0){
      toggle = 1;
      $("#toggle").html("On");}
    
    else{toggle = 0;
    $("#toggle").html("Off");}
    reset();
  });
  
  $("#mute").click(function(){
    if(mute==0){
      mute = 1;
      $("#audio").html("Off");
    } else {
      mute= 0;
      $("#audio").html("On");
    }
  })
  
  //Green button click
$("#green").click(function(){
      $("#attempt").html("Let's do this!");
    $("#attempt").css("color","white");
  green();
  
  //logs players attempts
  attempt.push(green);
  
  //tests against master
  if(master[clicks]==green){
  
    //feedback
    console.log("ok - green");
    successProcess();
  }else{
    console.log("error - green");
    $("#attempt").html("Error");
    $("#attempt").css("color", "red");
    if(toggle ==1){
    reset();}
    else{
      attempt = [];
    clicks = 0;
    compGo();
    }}
});  
  
    //Red button click
$("#red").click(function(){
      $("#attempt").html("Let's do this!");
    $("#attempt").css("color","white");
  red();
  attempt.push(red);
    if(master[clicks]==red){
    console.log("ok - red");
    successProcess();
  }else{
    console.log("error - red");
    $("#attempt").html("Error");
        $("#attempt").css("color", "red");
        if(toggle ==1){
    reset();}
    else{
      attempt = [];
    clicks = 0;
    compGo();
    }}   
});  
  
  //Yellow button click
$("#yellow").click(function(){
      $("#attempt").html("Let's do this!");
    $("#attempt").css("color","white");
  yellow();
  attempt.push(yellow);
    if(master[clicks]==yellow){
    console.log("ok - yellow");
      successProcess();
  }else{
    console.log("error - yellow");
    $("#attempt").html("Error");
        $("#attempt").css("color", "red");
        if(toggle ==1){
    reset();}
    else{
      attempt = [];
    clicks = 0;
    compGo();
    }}
});  
  
  //Blue button click

  $("#blue").click(function(){
     $("#attempt").html("Let's do this!");
    $("#attempt").css("color","white");
    blue();
  attempt.push(blue);
      if(master[clicks]==blue){
    console.log("ok - blue");
        successProcess();
  }else{
    console.log("error - blue");
    $("#attempt").html("Error");
        $("#attempt").css("color", "red");
        if(toggle ==1){
    reset();}
    else{
      attempt = [];
    clicks = 0;
    compGo();
    }}
});

  
  
 
  
  

  
 
  
  
  
  compGo();
  
  
  
}); //ends document ready

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console