Coding to Display Result
-
Hello The current result display is like: 2 / 5 – 40%
Is there anyway that I can show it like:
correct Answers: 2
Incorrect Answers: 2
Unanswered Questions: 1
Percentage: 40%PS. Around 5 years ago i had designed a site for my client and had asked the same question from you. you developed the following code to put in functions.php. I had saved that with me. But somehow this code is not working..! it is not displaying the result i want. instead it is showing the same result as (2 / 5 – 40%). Code was:
function 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 Answers";
} else {
sel = jQuery(this).find(".hdq_wrong");
if(sel.length > 0){
data = "Incorrect Answers";
} else {
data = "No Answers Selected";
no_answers ++;
}
}
}
jQuery("<div class='online-result-status'><h1>" + data +"</h1></div>").prependTo(this);
});
// hdq_score is array of score (score/total questions)
let c = hdq_score[0];
let t = hdq_score[1];
let q = parseFloat(t)-parseFloat(c)-no_answers;
q = q.toFixed(0);
let p = (parseFloat(c) / parseFloat(t)) * 100;
p = p.toFixed(2);
let d =<br> <br> <br> <p class="Online-Test-result-sheet"><br> <br> <br> Correct Answers: <strong>${c}</strong><br/><br> Incorrect Answers: <strong>${q}</strong><br/><br> Unanswered Questions: <strong>${no_answers}</strong><br/><br> Percentage: <strong>${p}%</strong><br> </p><br>;
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');
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Coding to Display Result’ is closed to new replies.