Seventh challenge #7
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Challenge requirements
Build a function constructor called Question to describe a question. A question should include: a) the question itself, b) the answers, c) the correct answer.
Create a couple of questions using the constructor.
Store them all inside an array.
Select one random question and log it on the console, together with the possible answers (each question should have a number).
Use the 'prompt' function to ask the user for the correct answer such as you displayed it on task 4.
Check if the answer is correct and print to the console whether the answer is correct or not.
Suppose this code would be a plugin for other programmers to use in their code. So make sure all your code is private and doesn't interfere with the other programmers code.
After you display the result, display the next random question, so that the game never ends.
Be careful: after task 8, the game literally never ends. So include the option to quit the game if the user writes 'exit' instead of the answer.
Track the user's score to make the game more fun. So each time an answer is correct, add 1 point to the score.
Display the score in the console.
Verification steps
Download all the files into a folder and then open the index.html file on a browser.
Enter 'exit' in the prompt that pops up, then proceed to inspect the site and open the console.
Once the console has been opened, reload the site.
Answer the questions on the prompt.
Check that your score increments if you answer correctly.
Check that the game can be ended by typing 'exit' in the prompt and that it shows your final score correctly.