Created
February 25, 2019 19:37
-
-
Save akornor/02de917c502529bb4068313b4606c58f to your computer and use it in GitHub Desktop.
guessletter.js
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
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