Skip to content

feat: quiz scores are calculated and displayed client-side only with no persistence — scores are lost on page refresh and no progress tracking, leaderboard, or history exists despite being listed as a Future Enhancement #168

Description

@divyanshim27

Summary

quiz.html (232 lines, fully reviewed) implements a complete quiz engine
with timer, score tracking, progress bar, and results display — entirely
in client-side JavaScript (scripts/quiz.js + scripts/quiz-data.js).

The results section renders:

<span id="finalScore" class="result-value">0/10</span>
<span id="timeTaken" class="result-value">00:00</span>
<span id="correctAnswers" class="result-value">0</span>
<span id="incorrectAnswers" class="result-value">0</span>

But these values are never sent to the Flask backend. The moment the
user navigates away, refreshes, or closes the tab — all quiz results
are permanently lost. There is no score history, no progress tracking,
and no foundation for the Leaderboard system listed under
Future Enhancements.

Concrete User Impact

  • A student completes the Web Development Quiz scoring 9/10 in 4:32 —
    closes the tab — score is gone forever
  • There is no "My Results" page because no results are ever persisted
  • The AI guidance feature (ai.html) cannot personalize recommendations
    based on quiz performance because performance data is never stored
  • The future Leaderboard cannot be built without a database-backed
    score persistence layer

Why This Blocks Future Features

The README lists these under Future Enhancements:

  • Leaderboard system — requires stored scores per user per quiz
  • Advanced learning analytics — requires historical score data
  • Enhanced AI personalization — requires knowing what a user
    scored on which topics to tailor guidance

None of these can be implemented without this foundation.

Proposed Fix

1. Backend endpoint for score persistence:

# backend/app.py
from datetime import datetime

@app.route("/api/quiz/submit", methods=["POST"])
def submit_quiz():
    if "user_id" not in session:
        return jsonify({"error": "Unauthorized"}), 401

    data = request.get_json()
    # Store: user_id, course, score, total, time_taken, completed_at
    save_quiz_result(
        user_id=session["user_id"],
        course=data["course"],           # "webdev", "ai", "career"
        score=data["score"],
        total=data["total"],
        time_taken=data["timeTaken"],
        completed_at=datetime.utcnow()
    )
    return jsonify({"status": "saved"})

@app.route("/api/quiz/history")
def quiz_history():
    if "user_id" not in session:
        return jsonify({"error": "Unauthorized"}), 401
    return jsonify(get_user_quiz_history(session["user_id"]))

2. Frontend — POST results on quiz submission:

// scripts/quiz.js — add after displaying results:
async function saveResult(course, score, total, timeTaken) {
    await fetch("http://127.0.0.1:5000/api/quiz/submit", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        credentials: "include",
        body: JSON.stringify({ course, score, total, timeTaken })
    });
}
// Call saveResult() inside the existing submitQuiz() handler

3. Add /history page showing past attempts per course.

Acceptance Criteria

  • POST /api/quiz/submit endpoint saves score, course, time, timestamp
  • Results saved to SQLite via backend/app.py
  • scripts/quiz.js POSTs results to backend on quiz submission
  • GET /api/quiz/history returns user's past quiz results
  • New history.html page renders quiz history per course
  • Profile page updated to show most recent score per course

Labels: enhancement, backend, feature, level: intermediate

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions