Created
May 4, 2024 15:13
-
-
Save jvihrial/b4461ab399b5ccd746a7ca6c5241eb10 to your computer and use it in GitHub Desktop.
javascript console 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
const prompt = require('prompt-sync')({ sigint: true }); | |
const rawNumber = Math.random() * 10; | |
// Random number from 1 - 10 | |
const numberToGuess = Math.floor(rawNumber) + 1; | |
//console.log(rawNumber); | |
console.log(numberToGuess); | |
// This veriable is used to determine if the app should continue | |
let foundCorrectNumber = false; | |
while (foundCorrectNumber !== true) { | |
// get user input | |
let guess = prompt('Guess the number: '); | |
// convert the string input to a number | |
guess = Number(guess); | |
if (!Number.isInteger(guess)) { | |
console.log('Take this seriously bitch'); | |
continue; | |
} | |
// compare the guess to the secret answer and let the user know. | |
if (guess === numberToGuess) { | |
console.log('NEEEEERD'); | |
foundCorrectNumber = true; | |
break; | |
} | |
if (guess < numberToGuess) { | |
console.log('Thats too small loser') | |
} else ( | |
console.log('Too big just like you lol') | |
) | |
} | |
console.log('OK bye ^_^'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment