Created
January 19, 2020 19:11
-
-
Save debonx/e57fb35cc4ff332e3bdcbc254b33c640 to your computer and use it in GitHub Desktop.
Node: User Input / Output 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
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 ... "); | |
} | |
} | |
} |
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
let {testNumber} = require('./node-input-output-game-1.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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment