(function () { function initSDATest() { const root = document.getElementById("gg-sda-test"); if (!root || root.dataset.fixed === "yes") return; root.dataset.fixed = "yes"; const submit = root.querySelector("#gg-submit-btn"); const result = root.querySelector("#gg-result"); const reset = root.querySelector("#gg-reset-btn"); if (!submit || !result || !reset) { console.error("SDA Test buttons not found"); return; } let submitted = false; submit.addEventListener("click", function () { if (submitted) return; const questions = root.querySelectorAll(".gg-question"); let correct = 0; let wrong = 0; let unanswered = 0; questions.forEach(function (q) { const answer = Number(q.dataset.answer); const selected = q.querySelector("input:checked"); const options = q.querySelectorAll(".gg-option"); const review = q.querySelector(".gg-review"); if (!selected) { unanswered++; } else if (Number(selected.value) === answer) { correct++; } else { wrong++; } options.forEach(function (option, index) { option.querySelector("input").disabled = true; if (index === answer) { option.classList.add("gg-correct"); } if (selected && index === Number(selected.value) && index !== answer) { option.classList.add("gg-wrong"); } }); review.textContent = "Correct Answer: " + options[answer].innerText.trim(); review.hidden = false; }); const marks = correct - (wrong * 0.25); root.querySelector("#gg-marks").textContent = marks.toFixed(2) + " / 100"; root.querySelector("#gg-percentage").textContent = marks.toFixed(2) + "%"; root.querySelector("#gg-correct").textContent = correct; root.querySelector("#gg-wrong").textContent = wrong; root.querySelector("#gg-unanswered").textContent = unanswered; root.querySelector("#gg-result-message").textContent = "Your Mock Test 2 Result"; result.style.display = "block"; submit.disabled = true; submit.textContent = "TEST SUBMITTED"; submitted = true; result.scrollIntoView({ behavior: "smooth", block: "start" }); }); reset.addEventListener("click", function () { if (!confirm("Restart Mock Test?")) return; root.querySelectorAll("input[type=radio]").forEach(function (input) { input.checked = false; input.disabled = false; }); root.querySelectorAll(".gg-option").forEach(function (option) { option.classList.remove("gg-correct", "gg-wrong"); }); root.querySelectorAll(".gg-review").forEach(function (review) { review.hidden = true; review.textContent = ""; }); result.style.display = "none"; submit.disabled = false; submit.textContent = "SUBMIT TEST & VIEW RESULT"; submitted = false; root.scrollIntoView({ behavior: "smooth", block: "start" }); }); } initSDATest(); })();