Skip to content

Instantly share code, notes, and snippets.

@akornor
Created February 25, 2019 19:37
Show Gist options
  • Save akornor/02de917c502529bb4068313b4606c58f to your computer and use it in GitHub Desktop.
Save akornor/02de917c502529bb4068313b4606c58f to your computer and use it in GitHub Desktop.
guessletter.js
const letters_of_word = ['F', 'O', 'X']
let letters_of_guessed_word = ['_', '_', '_']
function guessLetter(letter){
for(let i=0; i < letters_of_word.length; i++){
if (letter === letters_of_word[i]){
letters_of_guessed_word[i] = letter
console.log(letters_of_guessed_word.join(''))
console.log(`congratulations letter ${letter} found.`)
break
}
// else{
// console.log(`letter ${letter} not found!`)
// continue
// }
}
const number_of_missing_letters = letters_of_guessed_word.filter(function(x){
return (x === '_')
}).length
if (number_of_missing_letters > 0){
console.log(`${number_of_missing_letters} letters remaining.`)
}else{
console.log('congratulations. You have won')
}
}
//tests
guessLetter('F')
guessLetter('A')
guessLetter('O')
guessLetter('X')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment