• Resolved mubasher99

    (@mubasher99)


    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 Coding

    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 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]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter mubasher99

    (@mubasher99)

    I have removed the test result sheet as the website was live.

    Although i can tell you here that result card looked like this:

    Correct Answers: 5
    Wrong Answers: 20 (this is where the problem is. My total questions in quiz are 20)
    Unanswered Questions: 7
    Percentage: 25.00%

    Thread Starter mubasher99

    (@mubasher99)

    It worked..!
    i have added

    let q = parseFloat(t)-parseFloat(c)-no_answers;
            q = q.toFixed(0); 

    in the // hdq_score is array of score (score/total questions) and changed ${p} into ${q} in the <p> section beneath.
    And it worked.
    Anyway thank for the code it helped me in resolving the issue ?? really a great Plugin

    Plugin Author Harmonic Design

    (@harmonic_design)

    Hi mubasher99,
    I’ve just released the next version of HD Quiz. The output is slightly different and modernized now, so you may need to do some small updates to that code.

    If you have issues, just let me know and I can help

    Thread Starter mubasher99

    (@mubasher99)

    Hello there..!
    I have just updated the plugin and guess what you are right, my all the quizzes crashed.
    I was receiving error like Question type not found.
    Thank God i had created backup before updating that. So i am back to my older version and looking forward for that additional code that could help me resolve the issue.

    Thread Starter mubasher99

    (@mubasher99)

    And thanks in advance for your concern and sincere guidance.. ??

    Plugin Author Harmonic Design

    (@harmonic_design)

    Hi mubasher99,
    I was referring to the javascript code I gave you that shows the extra data in the results. There should not be any issues like you are experiencing unless you didn’t upgrade your quiz/question data.

    If you have less than 60 questions, this should have been done automatically. However, if your server was unable to process 60 at once, or if you have more than 60 questions, then you should have been prompted with a big scary red notice letting you know that you need to run the manual data update tool.

    This upgrade tool can be found under the new tools sub navigation for HD Quiz. This tool runs at the click of a button and will loop through all of your questions and update the data as needed.

    The fact that you are getting Question type not found means that this data upgrade has not happened yet.

    Also, this version DOES NOT overwrite your old data in any way! So no need for backups if something does go wrong. You can simply deactivate/delete HD Quiz, then install the older version again and it will be like v1.8 never happened haha.

    Thread Starter mubasher99

    (@mubasher99)

    Yes you are right i have more than 60 question in each quiz. In fact i have more than 400 questions in most of the quizzes and two of my quizzes have over 800 questions..! Am i over burdening the plugin? is it safe to have that many questions?
    Moreover i have searched for the upgrade tool but haven’t found it any where. Will it be visible to me if i update the plugin? right now i am using the V.1.7

    Plugin Author Harmonic Design

    (@harmonic_design)

    The amount of questions a quiz can handle is limited only by how powerful your server is

    The upgrade tool is part of v1.8.

    When you update, goto the HD Quiz page and you should see a notice to upgrade your data to be compatible with the new version. If you don’t get this notice, then the tool can be found under the new tools submenu for HD Quiz.

    Once on the tool page, run the tool, then sit back and wait. With as many questions as you have, the update may take several minutes to complete. Just make yourself a coffee and wait until HD Quiz let’s you know that the upgrade has completed ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Total Number of “Incorrect Answers” in the result are always 20’ is closed to new replies.