20 General English Synonyms Quiz
const answers = {
q1:'c',q2:'b',q3:'b',q4:'b',q5:'b',q6:'b',q7:'b',q8:'b',q9:'a',q10:'a',
q11:'b',q12:'a',q13:'b',q14:'b',q15:'a',q16:'a',q17:'a',q18:'b',q19:'a',q20:'b'
};
function checkAnswers(){
let score=0;
const form=document.forms['quizForm'];
for(let q in answers){
const selected=form[q].value;
const qDiv=form[q][0].closest('.question');
qDiv.classList.remove('correct','wrong');
if(selected===answers[q]){
score++; qDiv.classList.add('correct');
} else qDiv.classList.add('wrong');
}
document.getElementById('result').innerHTML=`Your Score: ${score}/20 (${Math.round(score/20*100)}%)`;
window.scrollTo({top:0,behavior:'smooth'});
}
Leave a Reply