cert-study-app / static /script.js
Kentlo's picture
πŸš€ Clean deployment - removed all binary files
8f0fa74
let currentId = 100; // μ‹œμž‘ 문제 번호 (μƒ˜ν”Œ JSON이 100λ²ˆλΆ€ν„°λΌκ³  κ°€μ •)
async function loadQuestion(id) {
const res = await fetch(`/question/${id}`);
const q = await res.json();
if (q.error) {
document.getElementById("question-area").innerHTML = `<p>문제λ₯Ό 찾을 수 μ—†μŠ΅λ‹ˆλ‹€.</p>`;
return;
}
currentId = q.id;
let html = `<h2>${q.id}. ${q.question}</h2>`;
for (const [key, val] of Object.entries(q.options)) {
html += `<label><input type="radio" name="answer" value="${key}"> ${key}. ${val}</label><br>`;
}
html += `<button onclick="submitAnswer(${q.id})">제좜</button>`;
document.getElementById("question-area").innerHTML = html;
document.getElementById("result").innerHTML = "";
document.getElementById("next-btn").style.display = "none";
}
async function submitAnswer(id) {
const selected = document.querySelector("input[name='answer']:checked");
if (!selected) {
alert("닡을 μ„ νƒν•˜μ„Έμš”!");
return;
}
const res = await fetch("/check_answer", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({id: id, answer: selected.value})
});
const result = await res.json();
let msg = result.correct ? "βœ… μ •λ‹΅μž…λ‹ˆλ‹€!" : "❌ μ˜€λ‹΅μž…λ‹ˆλ‹€!";
msg += `<br>μ •λ‹΅: ${result.correct_answer}`;
msg += `<br>ν•΄μ„€: ${result.explanation}`;
document.getElementById("result").innerHTML = msg;
// "λ‹€μŒ 문제" λ²„νŠΌ ν‘œμ‹œ
document.getElementById("next-btn").style.display = "inline-block";
}
function nextQuestion() {
loadQuestion(currentId + 1);
}
// μ‹œμž‘ μ‹œ 첫 문제 λ‘œλ“œ
window.onload = () => {
loadQuestion(currentId);
};