Feature/fixed quiz scoring#56
Open
Prag-18 wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR resolves an issue in the quiz scoring system (
scripts/quiz.js) where the user's score could be artificially inflated. Previously, clicking a correct option repeatedly or toggling between options would continuously increment the score, allowing it to exceed the total number of questions in the quiz.To fix this, I introduced a robust state-tracking mechanism using a
userAnswersobject to map each question to its selected answer. The score is now dynamically recalculated whenever an answer changes, ensuring score consistency and preventing duplicate increments.🛠️ Changes Made
Resolved #16 Quiz Score Double-Counts on Option Re-Select
Added Answer Tracking State
userAnswersstate object to store selections in the format:{ questionIndex: chosenOptionIndex }Reset State on Quiz Start
userAnswersinside thestartQuiz()function to ensure a clean state for every new quiz session.Dynamic Score Recalculation
Refactored
selectOption()to:userAnswersVisual Answer Persistence
Updated
showQuestion()to:userAnswersPrevented Redundant Operations
selectOption()when the user clicks an already selected option.🧪 How to Test / Reproduce
✅ Expected Behavior
✅ Expected Behavior
✅ Expected Behavior
✅ Result