Assignment Overview
This assignment adds a planned JavaScript feature to the Retro Terminal Trivia game. The feature will use at least one function to perform a mathematical calculation based on user input. In this case, the user input will come from the trivia answers selected during the quiz.
Feature Enhancement Note
Historical Score Tracking
After the quiz ends, JavaScript will calculate the user's final score and save the result using localStorage. This will allow the page to compare the current attempt with earlier attempts saved in the same browser.
The final result will show both the number of correct answers and the score percentage. For example, a user might see a result such as "8 out of 10 correct" and "80%."
In-Scope Feature Details
- Calculate the user's current trivia score after the quiz ends
- Display the current score as correct answers out of total questions
- Display the current score as a percentage
- Save the completed score using localStorage
- Display the previous attempt score
- Display the best score saved in the browser
- Display whether the user improved, declined, or matched the previous result
Out-of-Scope Feature Details
- Saving scores across different browsers or devices
- Creating user accounts or login features
- Using a database
- Creating a class leaderboard
- Collecting or storing personal user information
Planned JavaScript Calculation
The score percentage will be calculated by dividing the number of correct answers by the total number of questions, then multiplying the result by 100. This calculation will be placed inside a JavaScript function so it can be reused when the quiz ends.
function calculatePercentageScore(correctAnswers, totalQuestions) {
return Math.round((correctAnswers / totalQuestions) * 100);
}
Success Criteria
- The quiz calculates the user's score correctly
- The result displays as both a fraction and a percentage
- The score is saved in localStorage after the quiz ends
- The page displays the user's previous attempt score
- The page displays the user's best saved score
- The page displays a comparison message showing improvement, decline, or no change
- The feature remains appropriate for the current course level