Last active
October 23, 2021 12:06
-
-
Save midorikocak/789f20151ad8808c83483c83efaf8b9f to your computer and use it in GitHub Desktop.
Confirm, Prompt and Alert (Be careful, they are blocking)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> | |
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]--> | |
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]--> | |
<!--[if gt IE 8]> <html class="no-js"> <!--<![endif]--> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
<title></title> | |
<meta name="description" content="" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<link rel="stylesheet" href="" /> | |
</head> | |
<body> | |
<!--[if lt IE 7]> | |
<p class="browsehappy"> | |
You are using an <strong>outdated</strong> browser. Please | |
<a href="#">upgrade your browser</a> to improve your experience. | |
</p> | |
<![endif]--> | |
<script type="text/javascript"> | |
/* | |
* Steps: | |
* 1. I need to generate a random number. | |
* 2. I need to ask player the guess a number. | |
* 3. If number is bigger, answer is hot, if smaller, answer is cold. | |
*/ | |
// Game States: | |
// 1. game starts | |
// 2. ask a guess | |
// 3. If wrong or not exit, go to 2. | |
// 4. Right guess, show you win | |
// 5. Do you want to exit, yes | |
// Note: Prompt, Alert and Confirm is clocking the UI of the browser. Use carefully. | |
let randomNumber = Math.floor(Math.random() * 10); | |
let guessed; | |
let response = ""; | |
let exit = false; | |
do { | |
guessed = prompt("Please guess a number", "Enter a number"); | |
if (guessed > randomNumber) { | |
response = "hot"; | |
} else if (guessed < randomNumber) { | |
response = "cold"; | |
} | |
else{ | |
alert('congratulations'); | |
break; | |
} | |
if (confirm(response + " Do you want to continue?")) { | |
exit = false; | |
} else { | |
exit = true; | |
} | |
} while (guessed !== randomNumber && exit === false); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment