Created
January 11, 2020 12:00
-
-
Save debonx/e7d05e954f78335bfc0f813c36ba03a2 to your computer and use it in GitHub Desktop.
JavaScript: number guesser game with Node.js.
This file contains hidden or 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
let {testNumber} = require('./game.js'); | |
process.stdout.write("I'm thinking of a number from 1 through 10. What do you think it is? \n(Write \"quit\" to give up.)\n\nIs the number ... "); | |
let playGame = (userInput) => { | |
let input = userInput.toString().trim(); | |
testNumber(input); | |
}; | |
process.stdin.on('data', playGame); |
This file contains hidden or 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
let secretValue = Math.floor(1+Math.random()*10).toString(); | |
let numbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']; | |
module.exports = { | |
testNumber: (input) => { | |
if (input === 'quit') { | |
process.stdout.write('Ok. Bye!\n') | |
process.exit(); | |
} | |
if (!numbers.includes(input)) { | |
process.stdout.write('Choose a number from 1 through 10!\nIs the number ... ') | |
} else if (input === secretValue) { | |
process.stdout.write('Woah you got it! Are you psychic? See you later!\n') | |
process.exit(); | |
} else { | |
process.stdout.write("Nope. Guess again!\nIs the number ... "); | |
} | |
} | |
} |
Author
debonx
commented
Jan 11, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment