From e6fb123eb7f1fa7b8c0f75c269372165516d0a3d Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Wed, 28 Oct 2026 17:47:03 +0000 Subject: [PATCH] Add more question types --- frontend/js/fizika.js | 15 +++++++++------ frontend/js/load.js | 12 +++++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/frontend/js/fizika.js b/frontend/js/fizika.js index a220fad..11db731 100644 --- a/frontend/js/fizika.js +++ b/frontend/js/fizika.js @@ -141,8 +141,9 @@ async function ajaxLoad(type) { // its correct answer, and report whether they got it right. function gradeQuestion(question) { var div = "#feladat" + question.id; - var selected = `#question-${question.id}-answer-${question.correct}`; - var isCorrect = $(selected).is(":checked"); + var isCorrect = getAcceptedAnswers(question).some(function (answer) { + return $(`#question-${question.id}-answer-${answer}`).is(":checked"); + }); $(div).animate({ backgroundColor: isCorrect ? "#C6FF8C" : "#FF808C" }, 1100); return isCorrect; } @@ -183,10 +184,12 @@ function showCorrect() { reviewMode = 1; var percentage = scoreLoadedQuestions(); loadedQuestions.forEach(function (question) { - $(`label[for="question-${question.id}-answer-${question.correct}"]`).css( - "background-color", - "#C6FF8C", - ); + getAcceptedAnswers(question).forEach(function (answer) { + $(`label[for="question-${question.id}-answer-${answer}"]`).css( + "background-color", + "#C6FF8C", + ); + }); }); $("#percentage").html("Eredmény: " + percentage + "%"); $("#state").html("Helyes válaszok bejelölve!"); diff --git a/frontend/js/load.js b/frontend/js/load.js index 0f9a803..7b2175e 100644 --- a/frontend/js/load.js +++ b/frontend/js/load.js @@ -5,6 +5,10 @@ const QUESTION_COUNT_ERROR = `A feladatok mennyisége 1 és ${MAX_TOPIC_QUESTION const isValidQuestionCount = (count) => Number.isInteger(count) && count >= 1 && count <= MAX_TOPIC_QUESTIONS; +// Some official keys accept several choices, including withdrawn questions. +const getAcceptedAnswers = (question) => + (question.acceptedAnswers || [question.correct]).map(Number); + // Auto-detect API base URL const getApiBase = () => { const protocol = window.location.protocol; @@ -91,9 +95,10 @@ const loadQuestions = async ( // click handler; those were never removed, so they piled up across loads and // ended up grading stale (already-removed) questions, saving bogus 0% // results over the user's history. - loadedQuestions = currentQuestions.map(({ id, correct }) => ({ - id: Number(id), - correct: Number(correct), + loadedQuestions = currentQuestions.map((question) => ({ + id: Number(question.id), + correct: Number(question.correct), + acceptedAnswers: getAcceptedAnswers(question), })); totalPoints = loadedQuestions.length; @@ -326,6 +331,7 @@ const getMonthLabel = (monthValue) => { const knownLabels = { 1: "Május-Június", "1ma": "Május-Június (magyar, mint idegen nyelv)", + "2ma": "Május-Június (idegen nyelvű vizsga magyar változata)", 2: "Október-November", 3: "Harmadik időszak", m1: "1. Mintafeladatsor",