Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. var userGuess = Number(window.prompt("Pick a number between 1 and 10:",
  2. ""));
  3. var secretNumber = Math.floor(Math.random() * 10) + 1;
  4.  
  5. do {
  6. if (userGuess < secretNumber) {
  7. window.alert("A little low");
  8. document.write("<p>The secret number is... " + secretNumber + " and you
  9. guessed " + userGuess + "</p>");
  10. userGuess = Number(window.prompt("Pick another number between 1 and
  11. 10:", ""));
  12. } else if (userGuess > secretNumber) {
  13. window.alert("A little high");
  14. document.write("<p>The secret number is... " + secretNumber + " and you
  15. guessed " + userGuess + "</p>");
  16. userGuess = Number(window.prompt("Pick another number between 1 and
  17. 10:", ""));
  18. } else if (userGuess <= 0) {
  19. window.alert("Is not between 1 and 10");
  20. document.write("You guessed... " + userGuess + " this is not between 1
  21. and 10");
  22. userGuess = Number(window.prompt("Pick another number between 1 and
  23. 10:", ""));
  24. } else if (userGuess > 10) {
  25. window.alert("Is not between 1 and 10");
  26. document.write("You guessed... " + userGuess + " this is greater than
  27. 10");
  28. userGuess = Number(window.prompt("Pick another number between 1 and
  29. 10:", ""));
  30. }
  31. } while (userGuess != secretNumber);
  32.  
  33. document.write("Congratulations, you are correct! The number is " + userGuess + "!");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement