Skip to content

Commit

Permalink
Fixed bug that prevents proper exercise switching
Browse files Browse the repository at this point in the history
  • Loading branch information
kyletimmermans authored Jun 23, 2024
1 parent c6d7055 commit 2123afe
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 67 deletions.
110 changes: 63 additions & 47 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,57 @@ const comparative = () => {
}
};


const resetForm = () => {
// Reset Result and input answer field
document.getElementById("result").innerHTML = "Result: ";
document.getElementById("inputAnswer").value = "";

// Re-enable button
document.getElementById("check-button").disabled = false;

// Find out which exercise we need to get a new question from
// By looking at the current title that we set
currExerciseType = document.querySelector("#centered-title").textContent;

switch (currExerciseType) {
case "Verb Conjugations":
verb();
break;
case "Singular Noun Cases":
singNoun();
break;
case "Plural Noun Cases":
plurNoun();
break;
case "Singular Adjective Cases":
singAdj();
break;
case "Plural Adjective Cases":
plurAdj();
break;
case "Pronoun Cases":
pronoun();
break;
case "Possesive Pronoun + Сам Cases":
possesive();
break;
case "Demonstrative + Весь Cases":
demonstrative();
break;
case "Question Word Cases":
questionword();
break;
case "Comparative Creation":
comparative();
break;
default:
verb();
console.error("Something went wrong in checkAnswer()!");
}
};


const checkAnswer = () => {
let answer = document.getElementById("inputAnswer").value.toLowerCase();
if (answer.replace(/\s/g, "") == correctAnswer.toLowerCase()) {
Expand All @@ -675,56 +726,21 @@ const checkAnswer = () => {
}

// Disable button to prevent issues
var answerButton = document.getElementById("check-button");
answerButton.disabled = true;
document.getElementById("check-button").disabled = true;

// Wait 5 seconds for user to read corrected answer, then reset
setTimeout(() => {
// Reset Result and input answer field
document.getElementById("result").innerHTML = "Result: ";
document.getElementById("inputAnswer").value = "";
restForm();
}, 5000);
};

// Re-enable button
answerButton.disabled = false;

// Find out which exercise we need to get a new question from
// By looking at the current title that we set
currExerciseType = document.querySelector("#centered-title").textContent;
// Prevent timers from going off after exercise switch
function clearTimers() {
var id = window.setTimeout(function() {}, 0);
while (id--) {
window.clearTimeout(id);
}

switch (currExerciseType) {
case "Verb Conjugations":
verb();
break;
case "Singular Noun Cases":
singNoun();
break;
case "Plural Noun Cases":
plurNoun();
break;
case "Singular Adjective Cases":
singAdj();
break;
case "Plural Adjective Cases":
plurAdj();
break;
case "Pronoun Cases":
pronoun();
break;
case "Possesive Pronoun + Сам Cases":
possesive();
break;
case "Demonstrative + Весь Cases":
demonstrative();
break;
case "Question Word Cases":
questionword();
break;
case "Comparative Creation":
comparative();
break;
default:
verb();
console.error("Something went wrong in checkAnswer()!");
}
}, 5000);
};
resetForm();
}
20 changes: 10 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@
<div class="dropdown position-fixed top-0 start-0 p-2">
<button class="btn btn-info dropdown-toggle" type="button" id="dropdownMenu2" data-bs-toggle="dropdown" aria-expanded="false">Exercise Type </button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu2">
<li><button class="dropdown-item" type="button" onclick="verb()">Verb Conjugations</button></li>
<li><button class="dropdown-item" type="button" onclick="singNoun()">Singular Noun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="plurNoun()">Plural Noun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="singAdj()">Singular Adjective Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="plurAdj()">Plural Adjective Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="pronoun()">Pronoun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="possesive()">Possesive Pronoun + Сам Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="demonstrative()">Demonstrative + Весь Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="questionword()">Question Word Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="comparative()">Comparative Creation</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); verb();">Verb Conjugations</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); singNoun();">Singular Noun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); plurNoun();">Plural Noun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); singAdj();">Singular Adjective Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); plurAdj();">Plural Adjective Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); pronoun();">Pronoun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); possesive();">Possesive Pronoun + Сам Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); demonstrative();">Demonstrative + Весь Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); questionword();">Question Word Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); comparative();">Comparative Creation</button></li>
</ul>
</div>

Expand Down
20 changes: 10 additions & 10 deletions mobile/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@
<div class="dropdown top-0 start-0 p-2">
<button class="btn btn-info dropdown-toggle" type="button" id="dropdownMenu2" data-bs-toggle="dropdown" aria-expanded="false">Exercise Type </button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu2">
<li><button class="dropdown-item" type="button" onclick="verb()">Verb Conjugations</button></li>
<li><button class="dropdown-item" type="button" onclick="singNoun()">Singular Noun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="plurNoun()">Plural Noun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="singAdj()">Singular Adjective Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="plurAdj()">Plural Adjective Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="pronoun()">Pronoun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="possesive()">Possesive Pronoun + Сам Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="demonstrative()">Demonstrative + Весь Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="questionword()">Question Word Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="comparative()">Comparative Creation</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); verb();">Verb Conjugations</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); singNoun();">Singular Noun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); plurNoun();">Plural Noun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); singAdj();">Singular Adjective Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); plurAdj();">Plural Adjective Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); pronoun();">Pronoun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); possesive();">Possesive Pronoun + Сам Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); demonstrative();">Demonstrative + Весь Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); questionword();">Question Word Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="clearTimers(); comparative();">Comparative Creation</button></li>
</ul>
</div>

Expand Down

0 comments on commit 2123afe

Please sign in to comment.