Skip to content

Instantly share code, notes, and snippets.

@cindywu
Created January 4, 2023 18:05
Show Gist options
  • Save cindywu/b70041d074c68dce6a26523c79f40602 to your computer and use it in GitHub Desktop.
Save cindywu/b70041d074c68dce6a26523c79f40602 to your computer and use it in GitHub Desktop.
mastermind
// 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