|
Good Afternoon,
I have written the following script, but it's not meeting the requirements I have been given, but I am confused as to how to proceed:
I want to alter the script so that the secret number is between 1 and 100, and after each incorrect guess a hint is given about whether to guess higher or lower.
function game()
{
var secretnum = Math.floor(Math.random() * 100) + 1;
var guess = prompt("Enter a guess from 1 to 100", "");
var numguesses = 1;
while (guess != secretnum)
{
numguesses++;
guess = prompt("Wrong, try again with guess number " + numguesses, "");
}
alert("You guessed the number in " + numguesses + " guesses");
}
|
|
|
|
|
|
|
© Copyright codetoad.com 2001-2005 |
|
|