Skip to content

Instantly share code, notes, and snippets.

@Ge0rg3
Last active June 7, 2018 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ge0rg3/b2d3c36792c4216a8756e3b589ea4105 to your computer and use it in GitHub Desktop.
Save Ge0rg3/b2d3c36792c4216a8756e3b589ea4105 to your computer and use it in GitHub Desktop.
*Extremely* simple JS number guessing game.
var response = parseInt(prompt("Enter your number here."));
let attempts = 0;
random = (Math.floor(Math.random()*10));
while (response !== random) {
attempts++;
if (response > random) {
console.log(`Too high!`);
response = parseInt(prompt("Too high!"));
} else if (response < random) {
console.log(`Too low!`);
response = parseInt(prompt("Too low!"));
} if (response === random) {
alert(`Correct! This took you ${attempts} attempts!`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment