What I am currently doing is comparing user input to an array of answers without page refresh. This works fine.
What I need to achieve is to do the above and also compare the time the input was entered to seconds which is another value in the object. For simplity sake, let's say time is 20 at the moment. how do i do the comparsion
I have pushed answer into an array but i am opened to other methods.
[
{
"id": "1",
"seconds": "20",
"answer": "John"
},
{
"id": "2",
"seconds": "40",
"answer": "kwai"
}
]
JS
var score = 0;
var items = [];
$.getJSON('urlpath', function(data) {
$.each(data, function(key, val) {
items.push(val.answer);
});
$('#form_submit').click(function() {
var qS = $('#form_answer').val();
$.ajax({
type:"GET",
url:"",
data: qS,
datatype: 'html'
});
if ($.inArray(qS, items) > -1 ) {
//Do something
}
else {
//Do nothing
}
return false;
});
});