This website is the completed code for the fourth "challenge" of the course, to create a coding quiz, which included these instructions:
- Present coding questions to the user
- The quiz is timed; the score on the quiz reflects the amount of time left unused
- When a question is answered wrongly, time should be subtracted from the timer
- Provide the option to save initials to a high score list that is displayed and stored in localStorage for later use
- Developed wireframe and
html
code to display the coding quiz. - Used JavaScript to control the visibility of various sections of the webpage using
style.display
. - Used JavaScript to manage the user's interaction with the coding quiz. This includes the timer, the display of questions, review of answers provided by the user, input of high-score initials, and the high score list display.
- An array of objects is used to store the quiz questions, which are drawn at random from this array.
- An array of objects is also used to store the high scores, which are uploaded to, and downloaded from,
localStorage
usingsetItem()
,getItem()
,JSON.stringify()
, andJSON.parse()
methods. - This challenge made heavy use of the
document.getElementById()
method to, for example, display questions (usingtextContent
), receiving questions (usingaddEventListener
), and for changing visibility, as noted above.
I believe the completed code meets the challenge criteria, however there is an item that could be improved. The code currently requires the correct answer string to match the id
of the element that contains the correct answer--and this is not necessarily obvious to a future editor of the code, which could lead to bugs. This is mentioned in the comments, which would probably avoid an issue. Nevertheless, I suspect there is a way to avoid having to match strings that are in two different files and I think this change would be an improvement. I have made this an issue on GitHub.
The live password generator webpage can be found at this link: https://stuart-rickard.github.io/coding-quiz/