Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ add another resource


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


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.


Auto Save

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.


<div class="container-fluid">
<h1>Number Guessing Game</h1>

<p>We have selected a random number between 1 and 100. See if you can guess it in 10 turns or fewer.
We'll tell you if your guess was too high or too low.</p>

<div class="form">
<label for="guessField">Enter a guess: </label><input type="text" id="guessField" class="guessField">
<input type="submit" value="Submit guess" class="guessSubmit">

<div class="resultParas">
<p class="guesses"></p>
<p class="lastResult"></p>
<p class="lowOrHi"></p>


                html {
font-family: sans-serif;

body {
width: 50%;
max-width: 200px;
min-width: 180px;
margin: 0 auto;
  text-align: center;

.lastResult {
color: white;
padding: 3px;


var randomNumber = Math.floor(Math.random() * 100) +1;

var guesses = document.querySelector(".guesses");
var lastResult = document.querySelector(".lastResult");
var lowOrHi = document.querySelector(".lowOrHi");

var guessSubmit = document.querySelector(".guessSubmit");
var guessField = document.querySelector(".guessField");

var guessCount = 1;
var resetButton;

function checkGuess() {
var userGuess = Number(guessField.value);
if (guessCount === 1) {
guesses.textContent = "Previous guesses: ";
guesses.textContent += userGuess + " ";
if (userGuess === randomNumber) {
lastResult.textContent = "Congratulations! You got it right!"; = "green";
lowOrHi.textContent = "";
} else if (guessCount === 10) {
lastResult.textContent = "!!!GAME OVER!!!";
} else {
lastResult.textContent = "Wrong!"; = "red";
if(userGuess < randomNumber) {
lowOrHi.textContent = "Last guess was too low!";
} else if(userGuess > randomNumber) {
lowOrHi.textContent = "Last guess was too high!";

guessField.value = "";
guessSubmit.addEventListener("click", checkGuess);

function setGameOver() {
guessField.disabled = true;
guessSubmit.disabled = true;
resetButton = document.createElement("button");
resetButton.textContent = "Start new game";
resetButton.addEventListener("click", resetGame);

function resetGame() {
guessCount = 1;

var resetParas = document.querySelectorAll(".resultParas p");
for (var i = 0 ; i < resetParas.length ; i++) {
resetParas[i].textContent = " ";


guessField.disabled = false;
guessSubmit.disabled = false;
guessField.value = " ";
guessField.focus(); = "white";

randomNumber = Math.floor(Math.random() * .100) + 1;