Task 10: Branching based on score

1.

Find the Hot Potatoes source folder, and copy the hp6hotpotnet.js_ file into your custom source folder.

2.

Open the file in your text editor, and search for the JavaScript Finish function. It's about a quarter of the way through the file, and it starts like this:

function Finish(){

3.

This function is useful to us because it's always called at the end of an exercise. If we want to insert any behaviour at the end of an exercise, we can put it inside this function. [Note: if you're going to post exercises on www.hotpotatoes.net, it's best not to mess with this function, in case you disrupt the submission of results!]

4.

The best place to insert our code is at the beginning of the function, right after the line that starts with "function". This is the code to insert:

if (Score>= 75) {
  alert("Well done! You passed!");
  window.location="http://www.google.com";
}
else{
  alert("Sorry! You scored less than 75%. Try again.");
  location.reload();
}

5.

Finally, we just need to comment our code:

function Finish(){
//MDH_Custom: Redirect the student based on score.
if (Score>= 75) {
  alert("Well done! You passed!");
  window.location="http://www.google.com";
}
else{
  alert("Sorry! You scored less than 75%. Try again.");
  location.reload();
}
//MDH_Custom: End of custom redirect code.

6.

Save the file, then create an exercise in JQuiz and view it in your browser. Here's an example.