From 404e81ad29c918ffe7927fdfc0e5d7a3c1d5fda8 Mon Sep 17 00:00:00 2001 From: sascha Date: Wed, 28 Jan 2026 18:51:25 +0000 Subject: [PATCH] app/static/script.js aktualisiert --- app/static/script.js | 65 ++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/app/static/script.js b/app/static/script.js index 1d5b135..fb2e2ef 100644 --- a/app/static/script.js +++ b/app/static/script.js @@ -36,7 +36,7 @@ function fetchPages(type) { const list = document.getElementById('page-list'); list.innerHTML = ''; - selectedPages = []; // Standard: Nichts ausgewählt + selectedPages = []; updatePageDisplay(); pages.forEach(p => { @@ -96,16 +96,15 @@ function nextQuestion() { const btn = document.getElementById('btn-action'); const fb = document.getElementById('feedback'); - // Button zurücksetzen auf "Prüfen" btn.innerText = "Prüfen"; btn.onclick = checkAnswer; - btn.className = "action-btn primary"; // Farbe Grün + btn.className = "action-btn primary"; fb.innerText = ''; fb.className = 'feedback'; document.querySelectorAll('input').forEach(i => i.value = ''); - attempts = 0; // Versuche resetten + attempts = 0; fetch('/api/question', { method: 'POST', @@ -182,31 +181,54 @@ function checkAnswer() { .then(res => res.json()) .then(res => { const fb = document.getElementById('feedback'); - fb.innerText = res.msg; if (res.status === 'correct') { - // RICHTIG -> Button auf "Weiter" schalten + // Richtig -> Sofort grün und weiter + fb.innerText = res.msg; fb.className = 'feedback correct'; stats.correct++; switchToNextMode(); + } else if (res.status === 'typo') { + // Tippfehler -> Warnung, zählt als Versuch + fb.innerText = res.msg; fb.className = 'feedback typo'; attempts++; - checkAttempts(res.msg); // Typo zählt auch als Versuch + checkAttempts(); + } else { - // FALSCH - fb.className = 'feedback wrong'; + // Falsch attempts++; - checkAttempts(res.msg); + if (attempts < 3) { + fb.innerText = `Falsch. Versuch ${attempts}/3. Probiere es noch einmal!`; + fb.className = 'feedback wrong'; + // Button bleibt auf "Prüfen", man kann es nochmal versuchen + } else { + checkAttempts(); // Lösen + } } }); } -function checkAttempts(msg) { +function checkAttempts() { + // Wenn 3 mal falsch (oder aufgegeben wird) if (attempts >= 3) { - // Zu viele Versuche -> Button auf "Weiter" - document.getElementById('feedback').innerText = "Leider falsch (3 Versuche). " + msg; - stats.total++; // Zählt als fertig (aber falsch) + const fb = document.getElementById('feedback'); + let solution = ""; + + // Lösungstext zusammenbauen + if (currentCard.type === 'vocab') { + solution = currentCard.answer; + } else if (currentCard.type === 'irregular_standard') { + solution = `${currentCard.answer_simple} -> ${currentCard.answer_participle}`; + } else { + solution = `${currentCard.answer_infinitive} -> ${currentCard.answer_simple} -> ${currentCard.answer_participle}`; + } + + fb.innerText = `Leider nicht geschafft. Lösung: ${solution}`; + fb.className = 'feedback wrong'; + + stats.total++; updateStats(); switchToNextMode(); } @@ -215,14 +237,19 @@ function checkAttempts(msg) { function switchToNextMode() { const btn = document.getElementById('btn-action'); btn.innerText = "Weiter"; - btn.onclick = finishTurn; // Beim Klick auf Weiter -> finishTurn + btn.onclick = finishTurn; btn.focus(); } function finishTurn() { // Wenn "Weiter" geklickt wird if (document.getElementById('btn-action').innerText === "Weiter") { - if(attempts < 3) stats.total++; // Wenn richtig, hier Zähler hoch + // Nur wenn es beim ersten Mal oder nach Typo geklappt hat, zählt es als "correct" für die Statistik + // Die Logik oben (bei status correct) hat stats.correct++ schon gemacht. + // Hier zählen wir nur total hoch, wenn es noch nicht passiert ist (bei failure passierte es schon) + if (attempts < 3 && document.getElementById('feedback').classList.contains('correct')) { + stats.total++; + } updateStats(); nextQuestion(); } @@ -235,12 +262,8 @@ function updateStats() { document.getElementById('stats-text').innerText = `${p}% Richtig (${stats.correct}/${stats.total})`; } -// Enter Key: Klickt einfach den aktiven Button document.addEventListener('keypress', (e) => { if (e.key === 'Enter') { document.getElementById('btn-action').click(); } -}); - -function openPageOverlay() { document.getElementById('overlay').style.display = 'flex'; } -function closeOverlay() { document.getElementById('overlay').style.display = 'none'; } \ No newline at end of file +}); \ No newline at end of file