Add more question types

This commit is contained in:
Andras Schmelczer 2026-10-28 17:47:03 +00:00
commit e6fb123eb7
2 changed files with 18 additions and 9 deletions

View file

@ -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!");

View file

@ -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",