JSFiddle - React, Tailwind, and code Playground
HTML
<div id="score" style="font: bolder 20px courier">score: 0</div>
<input type="text" id="question" />
<input type="text" id="question1" />
JavaScript
var answers = {
'question': 'yes',
'question1': 'no',
};
var score = 0;
function checkResults() {
var $this = $(this),
val = $this.val().toLowerCase();
for (var k in answers) {
if (answers.hasOwnProperty(k)) {
if (k == $this.attr('id') && answers[k] === val) {
$this.css('background-color', 'green');
score += 1;
break;
} else {
$this.css('background-color', 'red');
}
}
}
if (score == 2) {
alert('Hi Ur Score is 2');
}
$('#score').text('score: ' + score);
}
$('input').on('keyup', checkResults);