From be3b3ad2f5ef8dcc8e5d5a2e224159eaee73b17f Mon Sep 17 00:00:00 2001 From: glendc Date: Thu, 8 Feb 2024 13:45:23 +0100 Subject: [PATCH] support skip button + improve wording (less negative) --- site/1/mathbox.html | 139 ++++++++++++++++++++++++++------------------ 1 file changed, 83 insertions(+), 56 deletions(-) diff --git a/site/1/mathbox.html b/site/1/mathbox.html index 3ae811b..f3ae82a 100644 --- a/site/1/mathbox.html +++ b/site/1/mathbox.html @@ -60,6 +60,7 @@ padding: 10px; margin: 10px; width: fit-content; + border-radius: 5px; } #exercise { @@ -79,8 +80,9 @@ input.split-part { text-align: center; - line-height: 1.75em; + line-height: 2em; border: 1px solid black; + border-radius: 5px; } #answer { @@ -207,6 +209,74 @@

wrongExercises: [], }; + function randomAnimal() { + const animals = [ + '🐶', '🦊', '🦄', '🐭', '🐼', '🐣', '🦉', + ]; + return animals[Math.floor(Math.random() * animals.length)]; + } + + function trackWrongExercise() { + const answerContext = document.getElementById("answer-context") ? document.getElementById("answer-context").value : "answer"; + + let exerciseString = ""; + switch (window.mathBoxState.exercise.exercise) { + case "som": + exerciseString = `som: ${window.mathBoxState.exercise.a} + ${window.mathBoxState.exercise.b} = ${window.mathBoxState.exercise.answer}`; + break; + case "verschil": + exerciseString = `verschil: ${window.mathBoxState.exercise.a} - ${window.mathBoxState.exercise.b} = ${window.mathBoxState.exercise.answer}`; + break; + case "splitsen": + if (answerContext === "a") { + exerciseString = `splitsen: ${window.mathBoxState.exercise.a} + ${window.mathBoxState.exercise.b} = ${window.mathBoxState.exercise.answer}`; + } else { + exerciseString = `${window.mathBoxState.exercise.a} + ${window.mathBoxState.exercise.b} = ${window.mathBoxState.exercise.answer}`; + } + break; + } + if (window.mathBoxState.wrongExercises[window.mathBoxState.wrongExercises.length - 1] !== exerciseString) { + window.mathBoxState.wrongExerciseCount += 1; + window.mathBoxState.wrongExercises.push(exerciseString); + + const skipButton = document.getElementById("button-skip"); + if (skipButton) { + skipButton.hidden = false; + } + } + } + + function nextExercise() { + if (window.mathBoxState.exerciseCount < window.mathBoxState.numExercises) { + console.log(answer, "correct, next exercise"); + generateExercise(); + } else { + console.log(answer, "correct, done"); + + console.log("show page result"); + document.getElementById("page-setup").hidden = true; + document.getElementById("page-exercises").hidden = true; + document.getElementById("page-result").hidden = false; + + const score = window.mathBoxState.exerciseCount - window.mathBoxState.wrongExerciseCount; + const total = window.mathBoxState.exerciseCount; + + // show confetti only at max score + document.getElementById("confetti").style.height = score === total ? '100vh' : '0'; + + const feedback = document.getElementById("result"); + feedback.innerHTML = `

🎉 klaar!

`; + feedback.innerHTML += `

${score} / ${total}

`; + if (window.mathBoxState.wrongExercises.length > 0) { + const animal = randomAnimal(); + feedback.innerHTML += `

${animal} bekijk goed:

`; + window.mathBoxState.wrongExercises.forEach((exercise) => { + feedback.innerHTML += `

${exercise}

`; + }); + } + } + } + function generateExercise() { window.mathBoxState.exerciseCount += 1; document.getElementById("exercise-feedback").innerHTML = " "; @@ -241,6 +311,7 @@

+ `; break; case "verschil": @@ -251,6 +322,7 @@

+ `; break; case "splitsen": @@ -283,6 +355,7 @@

} formExercise.innerHTML += ` + `; break; } @@ -293,6 +366,12 @@

answerEl.focus(); answerEl.click(); + document.getElementById("button-skip").addEventListener("click", (e) => { + e.preventDefault(); + trackWrongExercise(); + nextExercise(); + }); + document.getElementById("exercise").scrollTo({ behavior: "smooth", }) @@ -307,69 +386,17 @@

const answerContext = document.getElementById("answer-context") ? document.getElementById("answer-context").value : "answer"; if (answer == window.mathBoxState.exercise[answerContext]) { - if (window.mathBoxState.exerciseCount < window.mathBoxState.numExercises) { - console.log(answer, "correct, next exercise"); - generateExercise(); - } else { - console.log(answer, "correct, done"); - - console.log("show page result"); - document.getElementById("page-setup").hidden = true; - document.getElementById("page-exercises").hidden = true; - document.getElementById("page-result").hidden = false; - - const score = window.mathBoxState.exerciseCount - window.mathBoxState.wrongExerciseCount; - const total = window.mathBoxState.exerciseCount; - - // show confetti only at max score - document.getElementById("confetti").style.height = score === total ? '100vh' : '0'; - - const feedback = document.getElementById("result"); - feedback.innerHTML = `

🎉 Proficiat, je hebt alle oefeningen gemaakt!

`; - feedback.innerHTML += `

${score} / ${total}

`; - if (window.mathBoxState.wrongExercises.length > 0) { - if (window.mathBoxState.wrongExercises.length === 1) { - feedback.innerHTML += `

Je hebt deze oefening fout gemaakt:

`; - } else if (window.mathBoxState.wrongExercises.length > 1) { - feedback.innerHTML += `

Je hebt deze oefeningen fout gemaakt:

`; - } - window.mathBoxState.wrongExercises.forEach((exercise) => { - feedback.innerHTML += `

${exercise}

`; - }); - } - } + nextExercise(); } else { console.log(answer, "wrong, try again"); - const animals = [ - '🐶', '🦊', '🦄', '🐭', '🐼', '🐣', '🦉', - ]; - const animal = animals[Math.floor(Math.random() * animals.length)]; + const animal = randomAnimal(); document.getElementById("exercise-feedback").innerHTML = `${animal} Probeer het nog eens.`; document.getElementById("exercise-feedback").style.color = "red"; document.getElementById("answer").style.backgroundColor = "rgb(253, 220, 220)"; - let exerciseString = ""; - switch (window.mathBoxState.exercise.exercise) { - case "som": - exerciseString = `${window.mathBoxState.exercise.a} + ${window.mathBoxState.exercise.b} = ${window.mathBoxState.exercise.answer}`; - break; - case "verschil": - exerciseString = `${window.mathBoxState.exercise.a} - ${window.mathBoxState.exercise.b} = ${window.mathBoxState.exercise.answer}`; - break; - case "splitsen": - if (answerContext === "a") { - exerciseString = `${window.mathBoxState.exercise.a} + ${window.mathBoxState.exercise.b} = ${window.mathBoxState.exercise.answer}`; - } else { - exerciseString = `${window.mathBoxState.exercise.a} + ${window.mathBoxState.exercise.b} = ${window.mathBoxState.exercise.answer}`; - } - break; - } - if (window.mathBoxState.wrongExercises[window.mathBoxState.wrongExercises.length - 1] !== exerciseString) { - window.mathBoxState.wrongExerciseCount += 1; - window.mathBoxState.wrongExercises.push(exerciseString); - } + trackWrongExercise(); } }