Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getRandom() {
- var random = Math.floor(Math.random() * 20) + 1;
- return random;
- }
- var number = parseInt(prompt("What number do you want the computer to guess?"));
- var isGuessCorrect = false;
- var guesses = 0;
- while (!isGuessCorrect) {
- random = getRandom();
- if(random === number) {
- isGuessCorrect = true;
- }
- document.writeln(random + "<br>");
- ++guesses;
- }
- document.write("Computer guessed right after " + guesses + " guesses.");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement