Skip to content

Instantly share code, notes, and snippets.

@jgresalfi

jgresalfi/randNum.js

Last active Sep 4, 2016
Embed
What would you like to do?
Random number guessing game.
"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