-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
34 lines (28 loc) · 1.05 KB
/
script.js
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
let x = Math.floor(Math.random() * 10) + 1;
let y = Math.floor(Math.random() * 10) + 1;
let result = x * y;
let correctCount = 0;
let incorrectCount = 0;
let streakCount = 0;
document.getElementById("task").textContent = x + " * " + y + " = ?";
function checkResult() {
let userInput = document.getElementById("userInput").value;
if (userInput == result) {
correctCount++;
streakCount++;
newTask();
document.getElementById("correctCount").textContent = "Correct: " + correctCount;
document.getElementById("streakCount").textContent = "Streak: " + streakCount;
} else {
incorrectCount++;
streakCount = 0;
document.getElementById("wrongCount").textContent = "Incorrect: " + incorrectCount;
document.getElementById("streakCount").textContent = "Streak: " + streakCount;
}
}
function newTask() {
x = Math.floor(Math.random() * 10) + 1;
y = Math.floor(Math.random() * 10) + 1;
result = x * y;
document.getElementById("task").textContent = x + " * " + y + " = ?";
}