Chapter 2 Individual Case Study

> Planning JavaScript score calculation and result tracking...

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

Out-of-Scope Feature Details

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