Skip to content

Commit 4eed9b9

Browse files
Fix console error normalization for accurate comparison
- Normalize JavaScript error messages to match database expected outputs - Handle temporal dead zone errors (Cannot access before initialization) as ReferenceError - Handle ReferenceError, TypeError, and SyntaxError consistently - Ensure correct scoring when errors are the expected output - Fix console logic to properly validate error-based questions
1 parent cdfe52e commit 4eed9b9

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

src/App.jsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,40 @@ function App() {
494494
setStreak(0)
495495
}
496496
} catch (error) {
497+
// Normalize error messages to match database format
498+
let errorOutput = `Error: ${error.message}`
499+
500+
// Convert specific error messages to simple error types for comparison
501+
let normalizedError = errorOutput
502+
if (error.message.includes('Cannot access') && error.message.includes('before initialization')) {
503+
normalizedError = 'ReferenceError'
504+
} else if (error instanceof ReferenceError) {
505+
normalizedError = 'ReferenceError'
506+
} else if (error instanceof TypeError) {
507+
normalizedError = 'TypeError'
508+
} else if (error instanceof SyntaxError) {
509+
normalizedError = 'SyntaxError'
510+
}
511+
512+
const isCorrect = normalizedError === currentTopicQuestion.expectedOutput
513+
497514
setResult({
498-
output: `Error: ${error.message}`,
499-
isCorrect: false,
515+
output: errorOutput,
516+
isCorrect,
500517
expected: currentTopicQuestion.expectedOutput
501518
})
519+
520+
if (isCorrect) {
521+
setScore(score + 10)
522+
setStreak(streak + 1)
523+
setSnackbar({
524+
open: true,
525+
message: '🎉 Correct! Well done!',
526+
severity: 'success'
527+
})
528+
} else {
529+
setStreak(0)
530+
}
502531
}
503532
}
504533

0 commit comments

Comments
 (0)