jQuery(function($){$('.dqp-ui-quiz').each(function(){let b=$(this),q,i=0,score=0;let applyLink=b.data('link');let welcomeMsg=b.data('msg')||'🎉 Welcome! You are qualified for this exam.';try{q=JSON.parse(b.attr('data-questions'));}catch(e){b.html('Invalid JSON');return;}
function result(){if(score<9){b.html(`
❌ Try Again
Your Score: ${score}/${q.length}
Try Again
`);}else if(score===q.length){b.html(`
🎉 Congratulations!
${welcomeMsg}
Your Score: ${score}/${q.length}
${applyLink ? `
Apply for Job ` : ''}
`);}}
function render(){let p=Math.round((i/q.length)*100);b.html(`
`);q[i].options.forEach((o,x)=>{b.find('.quiz-options').append(`
${o}
`);});b.find('.quiz-option').click(function(){b.find('.quiz-option').removeClass('selected');b.find('input').prop('checked',false);$(this).addClass('selected').find('input').prop('checked',true);});b.find('.quiz-next').click(function(){let sel=b.find('input:checked');if(!sel.length)return alert('Select option');let x=sel.val(),opt=sel.closest('.quiz-option');if(x==q[i].answer){opt.addClass('correct');score++;}
else{opt.addClass('wrong');b.find(`input[value='${q[i].answer}']`).closest('.quiz-option').addClass('correct');}
setTimeout(()=>{i++;if(i>=q.length)result();else render();},700);});}
render();});});