Web Design and Development

Tutorial 6 - A simple maths game Part 1


Task 1 - Create your Web Page content

Create a file and save it as tutorial5.html.

HTML

Your Web Pages should follow the following specifications.

CSS

You will declare rules for 2 classes: correct and incorrect as follow:

JavaScript

Overview
Process
  1. Let's start with 1 question...
    1. Prompt the user with your first question, and store their answer in a variable.
    2. Display the text of that question in the question1 span, and the user's answer in the answer1 span. For example, if your first question is "8 + 7 = ... ", you can add the question to the question1 span by typing document.getElementById("question1").innerHTML="8 + 7 = ... ";
    3. Compare the answer with the correct answer
    4. If the answer was correct, add a tick symbol (✓) in the feedback1 span and add the class "correct" to that span (you can use document.getElementById("feedback1").classList.add("correct") for this
    5. . If the answer was incorrect, add the cross symbol (✗) in the feedback1 span and add the class "incorrect" to that span
  2. Test your code once with a correct answer and once with an incorrect answer
  3. If your code works as expected, repeat this for the second question.
  4. Test your code with a combination of correct and incorrect answers, then all correct and then all incorrect.
  5. If your code works, you could carry on and copy the same code for the 8 remaining questions... but before that, let's make a few optimisations...
  6. Once all the optimisations are in, copy your code for the remaining 8 questions, updating the ids to match the question numbers to make sure the code all works fine.
  7. Test that you code works with a combination of correct and incorrect answers
  8. Let's make the game a little bit more interesting and declare a variable that will count how many questions were answered correctly. Let's start by giving this a value of 0, and increment it each time the user gives a correct answer.
  9. Now that you have the number of correct answers, let's multiply this by 10 to get a mark out of 100, and display this score in the total score placeholder. Oh wait! There isn't a score placeholder! Let's jump to the HTML section, and add this placeholder, for example, you can create a new paragraph with some text such as "You Score:" followed by a span with id="score"
  10. Now add the score to the score placeholder and test your code a number of times.
  11. Make sure you understand everything in your code as we will continue with improving this in week 7, by developing the 2nd part of this game. Also feel free to add more CSS to improve the look and feel.

Task 2 - Validate your code

Task 3 - Upload your page to the Web server and set the correct permissions

Task 4 - Share your design with your peers and comment on other's work.


Prepared by Anne-Gaelle Colom,
Last modified, February 2024 by Daphne Economou
Accessibility statement