Skip to content

Commit 022e789

Browse files
committed
auto-proceed on correct answer
1 parent 435520f commit 022e789

5 files changed

Lines changed: 48 additions & 19 deletions

customary-units-three-numbers.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,13 +461,19 @@ clearBtn.onclick = () => scratchpad.clear();
461461

462462
// Event handlers
463463
function handleOptionClick(option, index) {
464-
const selectedAnswer = parseInt(option.textContent);
464+
const selectedAnswer = currentProblem.options[index];
465+
const isCorrect = selectedAnswer === currentProblem.answer;
465466

466-
if (selectedAnswer === currentProblem.answer) {
467-
animationSystem.handleCorrectAnswer(option, optionsContainer.getElementsByClassName('option'), () => {
467+
const allOptions = optionsContainer.querySelectorAll('.option');
468+
if (isCorrect) {
469+
animationSystem.handleCorrectAnswer(option, allOptions, () => {
470+
// Auto-proceed to the next problem
468471
if (currentProblemIndex < totalProblems - 1) {
469472
currentProblemIndex++;
470-
displayProblem();
473+
displayProblem();
474+
} else {
475+
console.log("Reached end of problems.");
476+
// Optionally disable next button or handle end state
471477
}
472478
});
473479
} else {

customary-units-up-to-100.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,13 +465,19 @@ clearBtn.onclick = () => scratchpad.clear();
465465

466466
// Event handlers
467467
function handleOptionClick(option, index) {
468-
const selectedAnswer = parseInt(option.textContent);
469-
470-
if (selectedAnswer === currentProblem.answer) {
471-
animationSystem.handleCorrectAnswer(option, optionsContainer.getElementsByClassName('option'), () => {
468+
const selectedAnswer = currentProblem.options[index];
469+
const isCorrect = selectedAnswer === currentProblem.answer;
470+
471+
const allOptions = optionsContainer.querySelectorAll('.option');
472+
if (isCorrect) {
473+
animationSystem.handleCorrectAnswer(option, allOptions, () => {
474+
// Auto-proceed to the next problem
472475
if (currentProblemIndex < totalProblems - 1) {
473476
currentProblemIndex++;
474-
displayProblem();
477+
displayProblem();
478+
} else {
479+
console.log("Reached end of problems.");
480+
// Optionally disable next button or handle end state
475481
}
476482
});
477483
} else {

length-word-problems.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,15 @@ document.addEventListener('DOMContentLoaded', () => {
339339
// Prevent clicking after answer
340340
if(option.disabled) return;
341341

342-
if (selectedAnswer === currentProblem.answer) {
343-
animationSystem.handleCorrectAnswer(option, optionsContainer.getElementsByClassName('option'), () => {
344-
// Don't auto-advance, let user click next
345-
// if (currentProblemIndex < totalProblems - 1) {
346-
// currentProblemIndex++;
347-
// displayProblem();
348-
// }
342+
const correctIndex = currentProblem.options.indexOf(currentProblem.answer);
343+
const isCorrect = index === correctIndex;
344+
345+
const allOptions = optionsContainer.querySelectorAll('.option');
346+
if (isCorrect) {
347+
animationSystem.handleCorrectAnswer(option, allOptions, () => {
348+
// Auto-proceed to the next problem using modulo logic
349+
currentProblemIndex = (currentProblemIndex + 1) % totalProblems;
350+
displayProblem();
349351
});
350352
} else {
351353
animationSystem.handleWrongAnswer(option);

metric-units-length.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,22 @@ clearBtn.onclick = () => scratchpad.clear();
426426
function handleOptionClick(option, index) {
427427
const problem = problems[currentProblem];
428428

429-
if (index === problem.correct) {
430-
animationSystem.handleCorrectAnswer(option, optionsContainer.getElementsByClassName('option'), () => {
429+
const correctIndex = problem.correct;
430+
const isCorrect = index === correctIndex;
431+
432+
// Use the animation system
433+
const allOptions = optionsContainer.querySelectorAll('.option');
434+
if (isCorrect) {
435+
animationSystem.handleCorrectAnswer(option, allOptions, () => {
436+
// Automatically load the next problem after the animation
431437
if (currentProblem < problems.length - 1) {
432438
currentProblem++;
433439
displayProblem();
440+
} else {
441+
// Optional: Handle end of problems, maybe disable next? Or loop?
442+
// For now, just log or do nothing if already at the end.
443+
console.log("Reached end of problems.");
444+
// Consider disabling next button here if desired: nextButton.disabled = true;
434445
}
435446
});
436447
} else {

time-problems.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ function handleClockNumberClick(selectedNumberElement, clickedNumber) {
391391

392392
const clockFace = optionsContainer.querySelector('.clock-face');
393393
if(clockFace) clockFace.appendChild(minuteHand);
394+
395+
// Automatically load the next problem
396+
generateAndShowNewProblem();
394397
});
395398
} else {
396399
// Use handleWrongAnswer, just passing the clicked number element
@@ -427,7 +430,8 @@ function handleSimpleOptionClick(selectedOption) {
427430

428431
if (isCorrect) {
429432
animationSystem.handleCorrectAnswer(selectedOption, elementsToDisable, () => {
430-
// REMOVED: setTimeout(displayProblem, 1500);
433+
// Automatically load the next problem
434+
generateAndShowNewProblem();
431435
});
432436
} else {
433437
animationSystem.handleWrongAnswer(selectedOption);

0 commit comments

Comments
 (0)