123

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <html>
  <head>
  <link href='https://fonts.googleapis.com/css?family=Chewy' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
  </head>
<body>
  <div id="container">
    <h1>Simon <i class="fa fa-registered"></i></h1>
    <div class="text-center">
      <button id = "reset" class = "btn btn-danger">Reset</button>
      <button id="start" class="btn btn-danger">Start</button>
    </div>
    <h2 class="text-center" id="prompt">Strict or Normal Mode?</h2>
    <div class="text-center" id="strictNorm">
      <button id="strict" class="btn btn-primary">Strict</button>
      <button id="norm" class="btn btn-success">Normal</button>
    </div>
    <div class="text-center">
      <h2 id="score">Count:</h2>
      <div class="text-center" id="scorekeeper"></div>
    </div>
    <div class="text-center" id="top">
      <p class = "pie" id="top-left"></p>
      <p class = "pie" id="top-right"></p>
    </div>
    <div class="text-center" id="bottom">
      <p class = "pie" id="bottom-left"></p>
      <p class = "pie" id="bottom-right"></p>
    </div>
  </div>
</body>

</html>
            
          
!
            
              body {
  background: url("https://goo.gl/1ODKqQ?gdriveurl") 30%;
}
h1 {
  font-family: 'Chewy', cursive;
  font-size: 50px;
  color: blue;
}
#container {
  text-align: center;
}
button {
  font-family: 'Chewy', cursive;
}
h2 {
  font-family: 'Chewy', cursive;
  color: red;
}
#scorekeeper {
  width: 50px;
  height: 50px;
  background: red;
  color: white;
  font-family: 'Chewy', cursive;
  text-align: center;
  margin-top:5px;
  margin-bottom: 5px;
  margin-right: auto;
  margin-left: auto;
  font-size: 30px;
  border-radius: 50px;
}
#score {
  color: green;
}
#top-left {
    background-color:green;
    height:150px;
    width: 150px;
    -moz-border-radius: 150px 0 0 0;
    border-radius: 150px 0 0 0;
  display:inline-block;
  margin:0;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
#top-right {
  background-color:red;
    height:150px;
    width: 150px;
    -moz-border-radius: 0 150px 0 0;
    border-radius: 0 150px 0 0;
  display: inline-block;
  margin: 0;
  -webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
#bottom-left {
  background-color:yellow;
    height:150px;
    width: 150px;
    -moz-border-radius: 0 150px 0 0;
    border-radius: 0 0 0 150px;
  display:inline-block;
  margin:0;
  -webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
#bottom-right {
  background-color:blue;
    height:150px;
    width: 150px;
    -moz-border-radius: 0 150px 0 0;
    border-radius: 0 0 150px 0;
  display: inline-block;
  margin: 0;
  -webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
#top {
  -webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
#bottom {
  -webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
            
          
!
            
              //A very special thank you to my Mom and sister and also to FCC Camper Andrew Naumann for all of their help! Thanks so much you guys...I appreciate it more than you know :) - Jessi

$(document).ready(function() {
  var cpuClicks = [];
  var userClicks = [];
  var level = 1;
  var color = "";
  var choices = ["green", "red", "yellow", "blue"];
  var move = choices[Math.floor(Math.random() * 4)];
  var score = 1;
  var strict = false;
  var index = 0;
  var playerTurn = false;
  var soundIndex;
  var soundOne = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3');
  var soundTwo = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound2.mp3');
  var soundThree = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound3.mp3');
  var soundFour = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound4.mp3');
  
  //hiding prompt
  $("#prompt").hide();
  $("#reset").hide();
  //choosing strict or normal
  $("#strictNorm").hide();
  $("#start").click(function() {
    $("#prompt").show();
    $("#strictNorm").show();
    //animation for prompt questions
    $("#prompt").removeClass("animated rotateOut");
    $('#prompt').addClass("animated swing");
  });
  //strict mode
  $("#strict").click(function() {
    strict = true;
    $("#start").hide();
    $("#reset").show();
    $("#strictNorm").hide();
    $("#prompt").removeClass("animated swing");
    $("#prompt").addClass("animated rotateOut");
  });
  //normal mode
  $("#norm").click(function() {
    strict = false;
    $("#start").hide();
    $("#reset").show();
    $("#strictNorm").hide();
    $("#prompt").removeClass("animated swing");
    $("#prompt").addClass("animated rotateOut");
  });
  //set back to original color for top left, top right, bottom left & bottom right
  function resetTL() {
    $("#top-left").css("background", "green");
  }
  function resetTR() {
    $("#top-right").css("background", "red");
  }
  function resetBL() {
    $("#bottom-left").css("background", "yellow");
  }
  function resetBR() {
    $("#bottom-right").css("background", "blue");
  }
  //transitioning color of circles and playing sounds
  //top left animation
  function topL() {
    $("#top-left").css("background", "#A9C52F");
    soundOne.play();
    setTimeout(resetTL, 400);
  }
//top right animation
  function topR() {
    $("#top-right").css("background", "#FF8A69");
    soundTwo.play();
    setTimeout(resetTR, 400);
  }
//bottom left animation
  function bottomL() {
    $("#bottom-left").css("background", "#FBFFA3");
    soundThree.play();
    setTimeout(resetBL, 400);
  }
  //bottom right animation
  function bottomR() {
    $("#bottom-right").css("background", "#106EE8");
    soundFour.play();
    setTimeout(resetBR, 400);
  }
  //allowing player to play only when true
 function player() {
   playerTurn = true;
 }
  //computers turn
 function cpuTurn() {
    var move = choices[Math.floor(Math.random() * 4)];
    if (move === choices[0]) {
      cpuClicks.push(1);
    }
    if (move === choices[1]) {
      cpuClicks.push(2);
    }
    if (move === choices[2]) {
      cpuClicks.push(3);
    }
    if (move === choices[3]) {
      cpuClicks.push(4);
    }
 }
  
  function pattern() {
    if(strict===false && cpuClicks.length===userClicks.length && cpuClicks[index]!==userClicks[index]) {
       var computer = setTimeout(cpuTurn, 1000);
       clearTimeout(computer);
    }
    else {
      cpuTurn();
    }
    for(var i = 0; i<cpuClicks.length; i++){
      doPattern(i);
    }
    console.log(cpuClicks);
  }
//function to control the pattern
  function doPattern(i) {
    setTimeout(function () {
      if (cpuClicks[i] === 1) {
        topL();
      }
      if (cpuClicks[i] === 2) {
        topR();
      }
      if (cpuClicks[i] === 3) {
        bottomL();
      }
      if (cpuClicks[i] === 4) {
        bottomR();
        }
      }, i * 1000);
    //player can only play when sequence is over...
    setTimeout(player, cpuClicks.length * 1000);
    }
  //reset the game
  function reset() {
    level = 1;
    score = 1;
    $("#scorekeeper").html("");
    $("#prompt").addClass("animated rotateIn");
    $("#start").show();
    $("#reset").hide();
    userClicks = [];
    cpuClicks = [];
    index = 0;
  }
  //changing the level prompt
   function levelNote() {
    if(level<21) {
    $("#prompt").html("Level" + " " + level + "!");
    $("#prompt").removeClass("animated rotateOut");
    $("#prompt").addClass("animated rotateInUpLeft");
    }
    else {
    $("#prompt").html("You Win!!!");
    $("#prompt").removeClass("animated rotateOut");
    $("#prompt").addClass("animated rotateInUpLeft");
      reset();
      return;
    }
  }
  //compare to see if right or wrong
  function compare() {
    if (userClicks[index] !== cpuClicks[index]) {
     if(strict===false) {
          playerTurn = false;
          $("#prompt").text("Oops! Incorrect - try again!");
          pattern();
          index = 0;
          userClicks = [];
      }
    if(strict===true) {
        $("#prompt").text("Oops! Incorrect - play again?");
        setTimeout(reset, 400);
      }
	 }
else {
		if (index === cpuClicks.length-1) {
					playerTurn = false;
					userClicks = [];
					level++;
          score++;
          $("#scorekeeper").html(score);
					levelNote();
					index = 0;
					pattern(cpuClicks);
				}
				else if (index!==cpuClicks.length-1) {
					index++;
					return;
			    console.log(userClicks);           
          console.log(userClicks[index]);
          console.log(cpuClicks[index]);
          }
      }
  }
  //actions when reset is pressed
  $("#reset").click(function() {
    $("#prompt").hide();
    $("#prompt").text("Strict or normal mode?");
    $("#reset").hide();
    $("#start").show();
    $("#strictNorm").hide();
    $("#prompt").removeClass("animated rotateOut");
    $('#prompt').addClass("animated rotateIn");
    reset();
  });
  //actions when start is clicked
  $("#start").click(function() {
    $("#prompt").text("Strict or normal mode?");
    $("#prompt").show();
    $("#strictNorm").show();
    //animation for prompt questions
    $("#prompt").removeClass("animated rotateOut");
    $('#prompt').addClass("animated rotateIn");
    reset();
  });
  $("#top-left").click(function() {
    if(playerTurn===true) {
      topL();
      userClicks.push(1);
      setTimeout(compare, 1000);
    }
  });
  $("#top-right").click(function() {
    if(playerTurn===true) {
      topR();
      userClicks.push(2);
      setTimeout(compare, 1000);
    }
  });
  $("#bottom-left").click(function() {
    if(playerTurn===true) {
      bottomL();
      userClicks.push(3);
      setTimeout(compare, 1000);
    }
  });
  $("#bottom-right").click(function() {
    if(playerTurn===true) {
      bottomR();
      userClicks.push(4);
      setTimeout(compare, 1000);
    }
  });
  function startGame() {
    levelNote();
    setTimeout(pattern,1000);
    $("#scorekeeper").html(score);
    }
  //user chooses strict or normal mode
  $("#strict").click(function() {
    strict = true;
    setTimeout(startGame, 2000);
  });
  $("#norm").click(function() {
    strict = false;
    setTimeout(startGame, 2000);
   });
});
            
          
!
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.

Console