I am having some difficulty comparing user-entered text in a textbox with an element in an array.
function checkUserInput()
{
var str = imageArray[randomNumber];
var index = str.indexOf(document.getElementById('textBox').value);
if(index == -1)
{
alert("Incorrect Answer");
}
else
{
alert("Correct Answer");
}
}
The user's input should either partially match the specified string in the array element and display "Correct Answer" or not match at all, resulting in displaying "Incorrect Answer".
<input type="text" id="textBox" value="">
<input type="button" value="Check" onclick="checkUserInput()">
I have included the code for the textbox and button for reference.