Created
September 4, 2016 20:17
-
-
Save jgresalfi/483bcceec7d2a2da223b7ecdf54736a0 to your computer and use it in GitHub Desktop.
Random number guessing game - refactor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var upper = 10000, | |
numToGuess = getRandomNumber(upper), | |
compGuess, | |
numOfGuesses = 0; | |
function getRandomNumber(upper) { | |
return Math.floor( Math.random() * upper ) + 1; | |
} | |
while ( compGuess !== numToGuess ) { | |
compGuess = getRandomNumber(upper); | |
numOfGuesses++; | |
} | |
console.log('Hooray! The number was: ' + numToGuess + '. And the computer guessed: ' + compGuess); | |
console.log('It took ' + numOfGuesses + ' to get it right.'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment