var isSearch = false; var totalPoints = 0; var loadedQuestions = []; var timer = 0; var startTimer = 0; var reviewMode = 0; function aspect() { if ($(window).width() > $(window).height()) { $("#cim").html("Fizika gyakorlás"); } else { $("#cim").html("Fizika"); } } async function ajaxLoad(type) { reviewMode = 0; totalPoints = 0; loadedQuestions = []; $("#state").html(""); $("#state2").html(""); $("#percentage").html(""); $("#megoldas").hide(); $("#loadingGif").show(); let result = ""; try { if (type == 1) { var source = "^" + $("#evszam").val() + $("#honap").val() + $("#feladat").val() + "$"; for (var i = 0; i <= 3; i++) { source = source.replace("all", ".*"); } result = await loadQuestions(true, undefined, source, 1000000); } else if (type == 2) { result = await loadQuestions( false, [ "mk", "md", "me", "mf", "mr", "h", "es", "ee", "ev", "m", "o", "ah", "am", "cs", "v", ], undefined, 15, ); } else { var NOQ = $("#numberof").val() ? $("#numberof").val() : 15; categories = [ $("#mk").prop("checked") ? "mk" : "", $("#md").prop("checked") ? "md" : "", $("#me").prop("checked") ? "me" : "", $("#mf").prop("checked") ? "mf" : "", $("#mr").prop("checked") ? "mr" : "", $("#h").prop("checked") ? "h" : "", $("#es").prop("checked") ? "es" : "", $("#ee").prop("checked") ? "ee" : "", $("#ev").prop("checked") ? "ev" : "", $("#m").prop("checked") ? "m" : "", $("#o").prop("checked") ? "o" : "", $("#ah").prop("checked") ? "ah" : "", $("#am").prop("checked") ? "am" : "", $("#cs").prop("checked") ? "cs" : "", $("#v").prop("checked") ? "v" : "", ]; result = await loadQuestions(false, categories, undefined, NOQ); } $("#loadingGif").hide(); $("#content").html(result); $("#state2").hide(); if ( result != '
' ) { $("#megoldas").show(); $("#state").html("Feladatok sikeresen letöltve!"); startTimer = 1; timer = 0; } } catch (error) { $("#loadingGif").hide(); $("#content").html(` `); $("#state").html("Hiba a feladatok betöltésekor"); console.error("Quiz loading error:", error); } } // Colour a single question green/red depending on whether the user selected // its correct answer, and report whether they got it right. function gradeQuestion(question) { var div = "#feladat" + question.id; var selected = "#form" + question.id + " #rad" + question.correct; var isCorrect = $(selected).is(":checked"); $(div).animate({ backgroundColor: isCorrect ? "#C6FF8C" : "#FF808C" }, 1100); return isCorrect; } // Grade every question currently on screen and return the score as a string // percentage (e.g. "66.67"). Grading the whole known set in one pass replaces // the old per-question click handlers, which accumulated across loads and // could save bogus results. function scoreLoadedQuestions() { var correctAnswersGiven = 0; loadedQuestions.forEach(function (question) { if (gradeQuestion(question)) correctAnswersGiven++; }); var percentage = (correctAnswersGiven / totalPoints) * 100; percentage = Math.round(percentage * 100) / 100; return percentage.toFixed(2); } // "Kiértékelés": grade the answers and, unless we are already reviewing, save // the result once. function evaluate() { if (!loadedQuestions.length) return; var percentage = scoreLoadedQuestions(); $("#percentage").html("Eredmény: " + percentage + "%"); $("#state").html("Válaszok leellenőrizve!"); if (isLocal && !reviewMode) { saveResult(percentage); reviewMode = 1; } } // "Helyes megoldások": reveal the correct answers. This is a review action, so // we enter review mode *before* grading to guarantee it can never overwrite a // previously saved result. function showCorrect() { if (!loadedQuestions.length) return; reviewMode = 1; var percentage = scoreLoadedQuestions(); loadedQuestions.forEach(function (question) { $("#label" + question.id + ".rad" + question.correct).css( "background-color", "#C6FF8C", ); }); $("#percentage").html("Eredmény: " + percentage + "%"); $("#state").html("Helyes válaszok bejelölve!"); $("#state2").show(); $("#state2").html( "(Ellenőrző mód, az itteni eredményeid nem kerülnek elmentésre, a módból való kilépéshez tölts be egy új tesztsort!)", ); } function saveResult(percentage) { var datum = new Date(); var ido = Math.round(timer / 60); localStorage["teszt" + numberOfPreviousTests] = percentage; localStorage["teszt" + numberOfPreviousTests + "date"] = datum.toLocaleDateString(); localStorage["teszt" + numberOfPreviousTests + "time"] = ido; localStorage["teszt" + numberOfPreviousTests + "total"] = totalPoints; startTimer = 0; timer = 0; $("#state2").show(); $("#state2").html( "Eredményed mentésre került! Ellenőrző módba belépve az eredményeid nem kerülnek tárolásra. A módból való kilépéshez tölts be egy új tesztsort!", ); eredmeny(); } function howMany() { var localString = "localStorage.teszt"; numberOfPreviousTests = 1; //number of previous tests+1 localString += numberOfPreviousTests; while (typeof eval(localString) !== "undefined") { numberOfPreviousTests++; localString = "localStorage.teszt" + numberOfPreviousTests; } } function eredmeny() { howMany(); if (isLocal) { if (typeof localStorage.teszt1 !== "undefined") { $("#tablazat").html( '| Dátum | Időtartam | Eredmény | Pontszám |
|---|