Is there a way to check for equality between two objects within an array?
In my website, I have a quiz with various input questions. The user's responses are stored in an array along with the question and correct answer.
Here is an example of the array structure:
var questions = [
[{
"q": "What is the capital of England?",
"ans": "london",
"userinput": "london"
}, {
"q": "What is the capital of Ireland?",
"ans": "dublin",
"userinput": "dublin"
}, {
"q": "What is the capital of France?",
"ans": "paris",
"userinput": "paris"
}, {
"q": "What is the captial of Spain?",
"ans": "london",
"userinput": "madrid"
}],
...
I am having trouble figuring out how to write the comparison if
statement. When I attempted it, I received a console message saying SyntaxError: Unexpected token {
.
I also want to include [$slide]
and [$qnum]
for code reusability on other pages.
if ($(questions[$slide][$qnum].userinput.val()) === $(questions[$slide][$qnum].ans.val())
...