JSFiddle - React, Tailwind, and code Playground
HTML
<div id="answer1"></div>
<div id="answer2"></div>
CSS
div{
background: gray;
padding: 10px;
margin: 10px 0;
}
JavaScript
let question = 1
let score = 0
$(document).ready(function () {
quiz()
$('#answer1').click(function () {
if (question === 1||3){
score++
console.log(question, score)
}
answer()
})
$('#answer2').click(function () {
if (question === 4||2){
score++
console.log(question, score)
}
answer()
})
});
function answer(){
question++
quiz()
}
function quiz(){
switch (question){
case 1:
score = 0
$('#answer1').html('Правильный');
$('#answer2').html('Не правельный');
break
case 2:
$('#answer1').html('Не правельный');
$('#answer2').html('Правильный');
break
case 3:
$('#answer1').html('Правильный');
$('#answer2').html('Не правельный');
break
case 4:
$('#answer1').html('Не правельный');
$('#answer2').html('Правильный');
break
case 5:
alert(score)
break
}
}