Quiz: "Back to the course" button only if 1 attempt is available

Quiz: "Back to the course" button only if 1 attempt is available

by Stefano Guglielmetti -
Number of replies: 8

Hi,
I have a problem with the quiz activity: I see the button "Back to the course" button only if I set an attempt available for the quiz.
Instead if you set 2 or more available attempts, when a user exceeds it on the first attempt, you only see the button "Retry the quiz" link.
This makes it difficult for users who do not understand why they have to do it again ...
Does anyone know if this situation is solvable?

Thanks

Average of ratings:Useful (1)
In reply to Stefano Guglielmetti

Re: Quiz: "Back to the course" button only if 1 attempt is available

by Dominique Bauer -
Piksa bilong Documentation writers Piksa bilong Particularly helpful Moodlers Piksa bilong Plugin developers

If you set the number of attempts to more than one, students can re-attempt quizzes if they wish. But they do not have to do so, hence the phrase "Re-attempt quiz" may be confusing if they are not aware of this.

You can change this phrase with "Re-attempt the quiz by clicking here * OR * return to course using the breadcrumb (above) or navigation menu (on the left)". This makes for a long button, but it works. See Language customisation◥ to see how to change phrases.

Average of ratings:Useful (3)
In reply to Dominique Bauer

Re: Quiz: "Back to the course" button only if 1 attempt is available

by Stefano Guglielmetti -
Hi Dominique and thanks for the reply.
I find the solution simple but aesthetically aberrant. I am very surprised that this situation is still present in the quizzes. Many of our users have serious difficulties understanding how to move, once the quiz is over.
I wonder if someone has not thought of putting the "return to course" button always visible at the end of the quiz. It would help a lot.
In reply to Stefano Guglielmetti

Re: Quiz: "Back to the course" button only if 1 attempt is available

by Sathiraju Sunkara -

Can You Please explain

In reply to Sathiraju Sunkara

Re: Quiz: "Back to the course" button only if 1 attempt is available

by Dominique Bauer -
Piksa bilong Documentation writers Piksa bilong Particularly helpful Moodlers Piksa bilong Plugin developers

Here's an improved answer, I hope, to Stefano's question. In my opinion, his request is justified and I think Moodle will one day incorporate a "Return to course" button.

In the meantime, you can easily insert such a button with the following JavaScript, placed in Site administration / Appearance / Additional HTML / Within HEAD and in which you just need to replace "https://moodleformulas.org" with the domain name of your Moodle site. Note that the script returns the user to the penultimate URL of the breadcrumb trail.

Formulas_20200901_1649.png

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
    if (window.location.href.indexOf("https://moodleformulas.org/mod/quiz/view.php") > -1) {
      $("<div style='text-align:center;'><button onclick='returntoCourse()' style='border:none;padding:7px 13px;'>Return to course</button></div>").insertBefore($("div.quizattempt"));
    }
})
function returntoCourse() {
var x = $("ol.breadcrumb li:eq(-2)  > a").attr("href");
window.location.replace(x);
}
</script>
In reply to Dominique Bauer

Re: Quiz: "Back to the course" button only if 1 attempt is available

by Dominique Bauer -
Piksa bilong Documentation writers Piksa bilong Particularly helpful Moodlers Piksa bilong Plugin developers

I see the button "Back to the course" button only if I set an [one] attempt available for the quiz.
Oops, I hadn't covered this case. So I added a line to the code to prevent the "Back to the course" button from appearing twice in this case. I also changed the name to "Back to the course" and use the same format as the existing button.

By the way, I like my button that returns to the current section better than Moodle's that returns to the main page of the course. smile

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
    if (window.location.href.indexOf("https://moodleformulas.org/mod/quiz/view.php") > -1) {
        if (!$(".continuebutton").length) {
            $("<div style='text-align:center;'><button type='submit' class='btn btn-secondary' onclick='backtotheCourse()'>Back to the course</button></div>").insertBefore($("div.quizattempt"));
        }
    }
})
function backtotheCourse() {
    var x = $("ol.breadcrumb li:eq(-2)  > a").attr("href");
    window.location.replace(x);
}
</script>
In reply to Dominique Bauer

Re: Quiz: "Back to the course" button only if 1 attempt is available

by Dominique Bauer -
Piksa bilong Documentation writers Piksa bilong Particularly helpful Moodlers Piksa bilong Plugin developers

I wonder if someone has not thought of putting the "return to course" button always visible at the end of the quiz.
Making the "Back to the course" button always visible will surely not be unanimous among developers. At best, this might not be seen as a priority. smile

Many of our users have serious difficulties understanding how to move, once the quiz is over.
Of course, the solution I am proposing should not make the situation even more difficult for users to understand. So I added a clear "OR" (although I don't think it's really necessary) between the "Back to the course" button and the "Re-attempt quiz" or "Continue the last attempt" button. I also use the code in all cases as I think it's clearer for users to go back to the current section than to the main page of the course.

Note that the script works well with the Boost theme in Chrome and Firefox on a Windows desktop computer. It might not work with other systems.

Stefano, if you use my code, I'd be curious if your users find the situation clearer or less clear than before.

Formulas_20200902_0017.png

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
    if (window.location.href.indexOf("https://moodleformulas.org/mod/quiz/view.php") > -1) {
        if ($(".continuebutton").length) {
            $(".continuebutton").css("display","none");
            $("<div style='text-align:center;'><button class='btn btn-secondary' onclick='backtotheCourse()'>Back to the course</button></div>").insertBefore($("div.quizattempt"));
        } else {
            $("<div style='text-align:center;'><button class='btn btn-secondary' onclick='backtotheCourse()'>Back to the course</button></div><div style='text-align:center;position:relative;top:8px;'>OR</div>").insertBefore($("div.quizattempt"));
        }
    }
})
function backtotheCourse() {
    var x = $("ol.breadcrumb li:eq(-2)  > a").attr("href");
    window.location.replace(x);
}
</script>

Don't forget to replace "https://moodleformulas.org" with the domain name of your Moodle site.

In reply to Dominique Bauer

Re: Quiz: "Back to the course" button only if 1 attempt is available

by Sathiraju Sunkara -
Can we use this code for assignment page by replacing "https://moodleformulas.org/mod/quiz/view.php" with "https://moodleformulas.org/mod/assign/view.php"