I'm building a click type game and I need to see if the answer the user selected is correct by comparing it to an array.
This is the JSON
{
quiztitle: "Select the States",
correct_answers: "9",
states: [
{
state_name: "Alabama",
image: "alabama_image",
answer: "correct"
},
{
state_name: "Alberta",
image: "alberta_image",
answer: "incorrect"
},
ect...
When a user clicks a button, it takes the value and needs to check if it's correct. What is the best way to do this.
This is my attempt so far:
$('body').on('click', '.matchBtns', function(){
var value = $(this.innerHTML);
if($.inArray(value, data.states)){
//its in the array
}else{
//its not
}
});
I'm unsure how to access the value 'answer' to check if correct or not
This is the html button
<button class="matchBtns">*State Name Here*</button>