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

              
                <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Guess the Number</title>
    <link href="style.css" rel="stylesheet">
</head>
<body>
    <header>
        <h1>Guess the Number</h1>
        <h2>You have three chances to guess the number I'm thinking of. Your only hint is that it's a number 1-20.</h2>
        <button onclick="guessTheNumber()">Start Guessing</button> 
    </header>

       
<script src="script.js" defer></script>
</body>
</html>
              
            
!

CSS

              
                body, h1, h2 {
    padding: 0;
    margin: 0;
    background-color: #9966ff;
}
header {
    margin-top: 10%;    
}

h1, h2 {
    text-align: center;
    padding: 0 30px 0 30px;
    font-family: sans-serif;
}

h1 {
    font-size: 36px;
}

h2 {
    margin-top: 10px;   
    font-size: 20px;
}

button {
    padding: 15px 35px 15px 35px;
    display: block;
    margin: 20px auto;
    border: none;
    background-color: #FFF;
    border-radius: 5px;
    font-size: 20px;
    cursor: pointer;
    transition: ease all 0.3s;
}

button:hover {
    background-color: #000;
    color: #FFF;
    
}
              
            
!

JS

              
                const chosenNumber = 18; 
let userGuessCount = 1; 
let userGuess = null;

function guessTheNumber() { 
  userGuess = prompt('Go ahead a take a guess.');
  if (userGuess === choseNumber) {
    alert('You win!');
  }
  while (userGuess !== chosenNumber && userGuessCount < 3) { 
    userGuess = prompt('Go ahead a take a guess.');
    userGuessCount++;
    if (userGuess === chosenNumber) {
        alert('You win!');
    } else if (userGuess > chosenNumber) {
      alert('Lower!');
    } else if (userGuess < chosenNumber) {
      alert('Higher!'); 
    }
  }
   
}

/*
function guessTheNumber() {      
    while (userGuess !== chosenNumber) {
        userGuess = prompt ('Go ahead a take a guess.');
        userGuessCount++; 
        if (userGuess <= chosenNumber - 1) {
            alert('Higher!');              
        } else {            
            if (userGuess >= chosenNumber + 1) {
            alert('Lower!');             
            }        
        } 
        if (userGuess == chosenNumber) {
            alert('You won!');
            break;
        } else {
            if (userGuessCount == 3) {
            alert('You failed! Try again?');   
            break;         
            }          
        }            
    } 
};*/
              
            
!
999px

Console