This is my code. I am trying to make the hangman app. How do I compare my user input "userGuess" to the array "array" that split out from the randomly generated word "word".
I want to say if the "userGuess" is equal to any of the values in the array "array" print to the console: userGuess + "is correct".
$(document).ready(function () { console.log("ready!");
var randomWords = [
"dog",
"cat",
"america",
"bootcamp",
"javascript",
"philadelphia"
]
var word = randomWords[Math.floor(Math.random() * randomWords.length)]; {
console.log(word);
}
var amount = word.length;
console.log(amount);
$("#display-word").on("click", function (event) {
$("#word").html("New Word is: " + amount + " letters long.")
})
//event listener
document.onkeyup = function (event) {
var userGuess = event.key;
console.log(userGuess);
$("#guesses").append(userGuess + "-");
var str = word;
var array = str.split("");
console.log(array);
for (var i = 0; i < array.length; i++) {
// console.log(array.length);
if (userGuess === i) {
console.log(userGuess + "is correct");
}
}
}//on key up
}); //doc.ready function