Total Number of “Incorrect Answers” in the result are always 20
-
Hello dear,
I am grateful to you that wrote that code for me. But one of my user notified me that when so ever test is submitted then Total number of Incorrect Answers in the result card are always 20(total questions in test). I had tried to understand the code but its above me. please help me solve the issue.Here is the code
/* ———————————————————————–*/
// HD Quiz Codingfunction hdq_before_mubasher99($quizID)
{
?>
<script>
function hdq_custom_submit(){
let data = {};
let no_answers = 0;// mark each question with string on whether answer was right, wrong, or unanswered
jQuery(“#hdq_<?php echo $quizID; ?> .hdq_question”).each(function(){
let data = “”;
if(!this.classList.contains(“hdq_question_title”) && !this.classList.contains(“hdq_results_wrapper”)){
let sel = jQuery(this).find(“.hdq_correct”);
if(sel.length > 0){
data = “Correct answer”;
} else {
sel = jQuery(this).find(“.hdq_wrong”);
if(sel.length > 0){
data = “Incorrect answer”;
} else {
data = “No answer selected”;
no_answers ++;
}
}
}jQuery(“<h2>” + data +”</h2>”).prependTo(this);
});// hdq_score is array of score (score/total questions)
let c = hdq_score[0];
let t = hdq_score[1];
let p = (parseFloat(c) / parseFloat(t)) * 100;
p = p.toFixed(2);
let d = `<p class=”Online-Test-result-sheet”>Correct Answers: <strong>${c}</strong><br/>
Wrong Answers: <strong>${t}</strong><br/>
Unanswered Questions: <strong>${no_answers}</strong><br/>
Percentage: <strong>${p}%</strong>
</p>`;
let results_section = document.querySelectorAll(“.hdq_result_fail”)[0];
results_section.insertAdjacentHTML(“beforebegin”, d);
return JSON.stringify(data); // expects a json string to be returned
}
</script>
<?php
}
add_action(‘hdq_before’, ‘hdq_before_mubasher99’);function hdq_submit_mubasher99($quizOptions)
{
array_push($quizOptions->hdq_submit, “hdq_custom_submit”);
return $quizOptions;
}
add_action(‘hdq_submit’, ‘hdq_submit_mubasher99’);The page I need help with: [log in to see the link]
- The topic ‘Total Number of “Incorrect Answers” in the result are always 20’ is closed to new replies.