Last active
December 26, 2018 15:16
-
-
Save sealucky7/a26a92549e4145fc64a9b762b48a9f79 to your computer and use it in GitHub Desktop.
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 words = [ | |
"programm", | |
"monkeys", | |
"lucky", | |
"javascript" | |
]; | |
let word = words[Math.floor(Math.random() * words.length)]; | |
let answerArray = []; | |
for(let i = 0; i < word.length; i++) { | |
answerArray[i] = "_"; | |
} | |
let remainingLetters = word.length; | |
while (remainingLetters > 0) { | |
alert(answerArray.join(" ")); | |
let guess = prompt("Guess the letter or click Cancel to exit the game."); | |
if (guess === null) { | |
break; | |
} else if (guess.length !== 1) { | |
alert("Please enter only one letter.") | |
} else { | |
for (let j = 0; j < word.length; j++) { | |
if (word[j] === guess) { | |
answerArray[j] = guess; | |
remainingLetters--; | |
} | |
} | |
} | |
} | |
alert(answerArray.join(" ")); | |
alert("Greate! It was a word " + word); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment