-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextracredit_3.html
More file actions
67 lines (57 loc) · 2.31 KB
/
Copy pathextracredit_3.html
File metadata and controls
67 lines (57 loc) · 2.31 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE html>
<html>
<head>
<title>Multiplication Practice</title>
</head>
<body>
<h1>Multiplication Practice</h1>
<div id="questionArea">
<!-- Question will be displayed here -->
</div>
<div id="answerArea">
<label for="answer">Your Answer:</label>
<input type="number" id="answer" min="0">
<button id="checkAnswer">Check Answer</button>
</div>
<div id="resultArea">
<!-- Result message will be displayed here -->
</div>
<script>
let correctAnswer;
let attempts = 0;
// Function to generate a random multiplication question
function generateQuestion() {
const num1 = Math.floor(Math.random() * 10); // Random number between 0 and 9
const num2 = Math.floor(Math.random() * 10); // Random number between 0 and 9
correctAnswer = num1 * num2;
const questionText = `How much is ${num1} times ${num2}?`;
document.getElementById("questionArea").textContent = questionText;
document.getElementById("answer").value = "";
document.getElementById("resultArea").textContent = "";
}
// Function to check the student's answer
function checkAnswer() {
const userAnswer = parseInt(document.getElementById("answer").value);
if (userAnswer === correctAnswer) {attempts = 0;
document.getElementById("resultArea").textContent = "Very good!"
generateQuestion();
} else {
attempts++;
if (attempts === 1) {
document.getElementById("resultArea").textContent = "No. Please try again.";
} else {
document.getElementById("resultArea").textContent = "No. Keep trying!";
}
}
}
// Generate the first question
generateQuestion();
// Attach event listener to the Check Answer button
document.getElementById("checkAnswer").addEventListener("click", checkAnswer);
// JavaScript code for the button to go back to Homework3.html
document.getElementById("goBackButton").addEventListener("click", function() {
window.location.href = "Homework3.html"; // Redirect to Homework3.html
});
</script>
</body>
</html>