Last active
September 4, 2016 20:16
-
-
Save jgresalfi/922576e4287b6aa3618213f48fe68767 to your computer and use it in GitHub Desktop.
Random number guessing game.
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 = getRandomNumber(upper), | |
numOfGuesses = 0, | |
correctGuess = false; | |
function getRandomNumber(upper) { | |
return Math.floor( Math.random() * upper ) + 1; | |
} | |
function guess() { | |
while ( correctGuess === false ) { | |
if (compGuess === numToGuess) { | |
console.log('Der Komputer ist smahter than you. The correct guess is: ' + numToGuess); | |
console.log('Der Komputer guessed: ' + numOfGuesses + ' in order to get it right.') | |
correctGuess = true; | |
} else { compGuess = getRandomNumber(10000); } | |
numOfGuesses++; | |
} | |
} | |
guess(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment