Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var userGuess = Number(window.prompt("Pick a number between 1 and 10:",
- ""));
- var secretNumber = Math.floor(Math.random() * 10) + 1;
- do {
- if (userGuess < secretNumber) {
- window.alert("A little low");
- document.write("<p>The secret number is... " + secretNumber + " and you
- guessed " + userGuess + "</p>");
- userGuess = Number(window.prompt("Pick another number between 1 and
- 10:", ""));
- } else if (userGuess > secretNumber) {
- window.alert("A little high");
- document.write("<p>The secret number is... " + secretNumber + " and you
- guessed " + userGuess + "</p>");
- userGuess = Number(window.prompt("Pick another number between 1 and
- 10:", ""));
- } else if (userGuess <= 0) {
- window.alert("Is not between 1 and 10");
- document.write("You guessed... " + userGuess + " this is not between 1
- and 10");
- userGuess = Number(window.prompt("Pick another number between 1 and
- 10:", ""));
- } else if (userGuess > 10) {
- window.alert("Is not between 1 and 10");
- document.write("You guessed... " + userGuess + " this is greater than
- 10");
- userGuess = Number(window.prompt("Pick another number between 1 and
- 10:", ""));
- }
- } while (userGuess != secretNumber);
- document.write("Congratulations, you are correct! The number is " + userGuess + "!");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement