-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleMathAI.html
More file actions
50 lines (46 loc) · 1.57 KB
/
SimpleMathAI.html
File metadata and controls
50 lines (46 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Math AI</title>
<script>
class MathAI {
constructor() {
this.history = [];
}
answerQuestion(question) {
try {
const answer = eval(question);
this.history.push({ question, answer, correct: true });
return answer;
} catch (error) {
this.history.push({ question, answer: null, correct: false });
return "Error: Invalid question.";
}
}
learnFromMistakes() {
this.history.forEach(entry => {
if (!entry.correct) {
console.log(`Reviewing question: ${entry.question}`);
// Logic to improve learning can be added here
}
});
}
}
const mathAI = new MathAI();
function askQuestion() {
const question = document.getElementById('questionInput').value;
const result = mathAI.answerQuestion(question);
document.getElementById('result').innerText = result;
mathAI.learnFromMistakes();
}
</script>
</head>
<body>
<h1>Math AI Assistant</h1>
<input type="text" id="questionInput" placeholder="Enter your math question">
<button onclick="askQuestion()">Ask</button>
<p id="result"></p>
</body>
</html>