Quiz Program – Part 1: the basic quiz

Step 7 – Adding a score

Code helper imageIf this is a quiz then we need to include a scoring system.

This involves using a variable to keep score with.

A variable is just an area of memory set aside to store a value. We already used a a variable – it was called answer and it stored the answer the player gave to the first question.

  1. Change your code in the two places shown in the screenshot – once towards top to set score to 0 and once in the right answer block to add one to it
  2. Code helper imageScore is a number, so it's easy to add or takeaway from it. If you wanted to be evil you could take a point away if the player gets the wrong answer...
  3. Run your code and check that it all works

Hmm, it might work, but it's difficult to tell. We need to print the score out to check.

  1. Add the line of code shown in the last screenshot

    Code helper imageThis needs to go right at the bottom of your program

  2. Now run the program again. Has everything worked? Is the score right?

    You probably need to check what happens if you get the answer wrong and what happens if you get it right.