Skip to content

Commit

Permalink
Fixed question generator firing twice bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kyletimmermans authored Jun 25, 2024
1 parent 633687f commit 86305e0
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 60 deletions.
82 changes: 42 additions & 40 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,17 +699,17 @@ const checkAnswer = () => {
checkButton.classList.remove('btn-outline-info');
checkButton.classList.add('btn-outline-warning');
checkButton.innerText = "Skip";
checkButton.onclick = resetForm;
checkButton.onclick = function() { resetForm(true); }

// Wait 5 seconds for user to read corrected answer, then reset
setTimeout(() => {
resetForm();
resetForm(true);
}, 5000);
};


// Onclick skip button, on change exercise, or 5s after clicking check-answer
const resetForm = () => {
const resetForm = (newQuestion) => {
var id = window.setTimeout(function() {}, 0);
while (id--) {
window.clearTimeout(id);
Expand All @@ -726,43 +726,45 @@ const resetForm = () => {
checkButton.classList.add('btn-outline-info');
checkButton.onclick = checkAnswer;

// 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;
if (newQuestion == true) {
// 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()!");
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 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="resetForm(); verb();">Verb Conjugations</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(); singNoun();">Singular Noun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(); plurNoun();">Plural Noun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(); singAdj();">Singular Adjective Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(); plurAdj();">Plural Adjective Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(); pronoun();">Pronoun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(); possesive();">Possesive Pronoun + Сам Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(); demonstrative();">Demonstrative + Весь Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(); questionword();">Question Word Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(); comparative();">Comparative Creation</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); verb();">Verb Conjugations</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); singNoun();">Singular Noun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); plurNoun();">Plural Noun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); singAdj();">Singular Adjective Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); plurAdj();">Plural Adjective Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); pronoun();">Pronoun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); possesive();">Possesive Pronoun + Сам Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); demonstrative();">Demonstrative + Весь Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); questionword();">Question Word Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); 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="resetForm(); verb();">Verb Conjugations</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(); singNoun();">Singular Noun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(); plurNoun();">Plural Noun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(); singAdj();">Singular Adjective Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(); plurAdj();">Plural Adjective Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(); pronoun();">Pronoun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(); possesive();">Possesive Pronoun + Сам Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(); demonstrative();">Demonstrative + Весь Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(); questionword();">Question Word Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(); comparative();">Comparative Creation</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); verb();">Verb Conjugations</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); singNoun();">Singular Noun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); plurNoun();">Plural Noun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); singAdj();">Singular Adjective Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); plurAdj();">Plural Adjective Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); pronoun();">Pronoun Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); possesive();">Possesive Pronoun + Сам Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); demonstrative();">Demonstrative + Весь Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); questionword();">Question Word Cases</button></li>
<li><button class="dropdown-item" type="button" onclick="resetForm(false); comparative();">Comparative Creation</button></li>
</ul>
</div>

Expand Down

0 comments on commit 86305e0

Please sign in to comment.