Write a script that plays a simple “guess the number” game with the user. It should select a random integer in the range [0 - 10], ask the user to guess the value, and provide feedback of the form “too high”, “too low”, or “congratulations” as appropriate. After the correct value is guessed, the script should terminate.
<!DOCTYPE html>
<html>
<head>
<title>Guess The Number</title>
</head>
<body>
<h1>Guess The Number</h1>
<script type="text/javascript">
var number = parseInt(Math.random()*10);
var guess = prompt("Please enter a number between 0-10");
while(number!=guess){
if(guess > number){
guess = prompt("Too High!!\nEnter again");
}else{
guess = prompt("Too Low!!\nEnter again");
}
}
alert("Congratulations!!")
</script>
</body>
</html>
Get Answers For Free
Most questions answered within 1 hours.