Created
January 4, 2023 18:05
-
-
Save cindywu/b70041d074c68dce6a26523c79f40602 to your computer and use it in GitHub Desktop.
mastermind
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
// cli or react? cli! | |
// start game | |
// make a guess | |
// see past guesses (if any) | |
// recieve response for guess | |
// colors: red, yellow, blue, green, purple, orange | |
const rl = require('readline').createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}) | |
const makeAGuess = () => { | |
let guess | |
rl.question('make a guess:', g => { | |
console.log(`you guessed: ${g}`) | |
guess = g | |
if (guess === secretCode) { | |
console.log('you win!') | |
rl.close() | |
} else { | |
console.log('try again') | |
// makeAGuess() | |
} | |
}) | |
} | |
const colors = [ | |
'r', | |
'y', | |
'b', | |
'g', | |
'p', | |
'o' | |
] | |
console.log('welcome to mastermind!') | |
let secretCode = '' | |
for (let i = 0; i < 4; i++) { | |
const randomIndex = Math.floor(Math.random() * colors.length) | |
secretCode += colors[randomIndex] | |
} | |
console.log(secretCode) | |
makeAGuess() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment