Fix syntax error in ternary operator for repeated 'don't know' detection

- Fixed malformed ternary operator in step-by-step mode
- Properly structured conditional logic for needsExplanationDueToRepeatedDontKnow
- Server now starts without syntax errors
This commit is contained in:
root
2025-06-30 15:42:04 +02:00
parent 9a7db8cff1
commit fd63a4617a

View File

@@ -657,6 +657,19 @@ class KidsAIExplorer {
// Pure "don't know" without additional thinking // Pure "don't know" without additional thinking
const isPureDontKnow = (hasDontKnowPhrase || isOnlyWhyQuestion || answer.trim().length < 5) && !hasSubstantialThinking && !isExpressingConfusion && !isAskingForHelp; const isPureDontKnow = (hasDontKnowPhrase || isOnlyWhyQuestion || answer.trim().length < 5) && !hasSubstantialThinking && !isExpressingConfusion && !isAskingForHelp;
// Check conversation history for repeated "don't know" responses
const conversationHistory = Array.from(this.conversationContainer.querySelectorAll('.user-message .message-content p'))
.map(p => p.textContent.toLowerCase().trim())
.slice(-3); // Last 3 user responses
const recentDontKnowCount = conversationHistory.filter(msg =>
msg.includes('weiß nicht') || msg.includes('weis nicht') || msg.includes('weiss nicht') ||
msg.includes("don't know") || msg.includes('i dont know') || msg.includes('keine ahnung')
).length;
// If child has said "don't know" multiple times recently, they need help
const needsExplanationDueToRepeatedDontKnow = recentDontKnowCount >= 2;
// Check if child is asking for a definition or explanation // Check if child is asking for a definition or explanation
const isAskingForDefinition = answerLower.startsWith('was ist') || answerLower.startsWith('what is') || const isAskingForDefinition = answerLower.startsWith('was ist') || answerLower.startsWith('what is') ||
answerLower.includes('was bedeutet') || answerLower.includes('what does') || answerLower.includes('was bedeutet') || answerLower.includes('what does') ||
@@ -670,9 +683,11 @@ class KidsAIExplorer {
let response; let response;
if (isExpressingConfusion || isAskingForHelp) { if (isExpressingConfusion || isAskingForHelp || needsExplanationDueToRepeatedDontKnow) {
// Child is expressing confusion or asking for help - provide a simple explanation // Child is expressing confusion, asking for help, or repeatedly saying "don't know" - provide explanation
console.log('📤 Sending explanation request for confused child or help request'); console.log('📤 Sending explanation request for confused child, help request, or repeated dont know');
const contextReason = needsExplanationDueToRepeatedDontKnow ? 'repeated_dont_know' : 'confusion_explanation';
response = await fetch('/api/respond-to-answer', { response = await fetch('/api/respond-to-answer', {
method: 'POST', method: 'POST',
@@ -684,11 +699,15 @@ class KidsAIExplorer {
question: currentQuestion, question: currentQuestion,
originalTopic: originalQuestion, originalTopic: originalQuestion,
language: this.currentLanguage, language: this.currentLanguage,
context: 'confusion_explanation', context: contextReason,
stepIndex: questionIndex, stepIndex: questionIndex,
instructions: this.currentLanguage === 'de' instructions: needsExplanationDueToRepeatedDontKnow
? 'Das Kind ist verwirrt und braucht eine einfache Erklärung. Gib eine klare, konkrete Antwort für Kinder. Erkläre das Konzept mit alltäglichen Beispielen. Verwende einfache Wörter und lade zum Ausprobieren ein. Keine weiteren Fragen stellen - erst erklären!' ? (this.currentLanguage === 'de'
: 'The child is confused and needs a simple explanation. Give a clear, concrete answer for children. Explain the concept with everyday examples. Use simple words and invite experimentation. Don\'t ask more questions - explain first!' ? 'Das Kind braucht jetzt eine einfache, klare Erklärung. Es hat bereits mehrmals "weiß nicht" gesagt oder ist verwirrt. Gib eine vollständige Antwort mit praktischen Beispielen. Erkläre das Konzept Schritt für Schritt mit alltäglichen Vergleichen. Keine weiteren Fragen - das Kind braucht Wissen!'
: 'The child needs a simple, clear explanation now. They have said "don\'t know" multiple times or are confused. Give a complete answer with practical examples. Explain the concept step by step with everyday comparisons. No more questions - the child needs knowledge!')
: (this.currentLanguage === 'de'
? 'Das Kind ist verwirrt und braucht eine einfache Erklärung. Gib eine klare, konkrete Antwort für Kinder. Erkläre das Konzept mit alltäglichen Beispielen. Verwende einfache Worte und lade zum Experimentieren ein. Keine weiteren Fragen - erst erklären!'
: 'The child is confused and needs a simple explanation. Give a clear, concrete answer for children. Explain the concept with everyday examples. Use simple words and invite experimentation. Don\'t ask more questions - explain first!')
}) })
}); });
} else if (isAskingForDefinition) { } else if (isAskingForDefinition) {