Keeping Score of quiz in javascript website

365 views Asked by At

We are creating a website in which homework (with about 10 multiple choice questions) will be graded. Each question is on their own HTML page. How do we tally the overall grade of the homework, while keeping track of each multiple choice question? (Deduct .33 points twice if wrong, then tally that score to a total score for the homework)

1

There are 1 answers

0
Cymen On

You need to have some state to persist the answers. There are a number of options including:

  • save the answer to the server for each question
  • save the answer to localStorage
  • save the answer in a cookie
  • save the answer in the URL as a query parameter

If you prefer to stay client side, I suggest using localStorage. It is a key-value store with some limitations on size but it should be a good fit for your problem.

My approach would be to store the answer into localStorage for each question. On the final page, I would load all the answers and perform the calculation for points.

MDN: localStorage