-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (26 loc) · 859 Bytes
/
index.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
35
36
37
const num1 = Math.ceil(Math.random() * 10);
const num2 = Math.ceil(Math.random() * 10);
const questionE1 = document.getElementById("question");
const inputE1 = document.getElementById("input")
const formE1 = document.getElementById("form");
const scoreE1 = document.getElementById("score")
let score = JSON.parse(localStorage.getItem("score"));
if(!score){
score = 0;
}
scoreE1.innerText = `score: ${score}`
questionE1.innerText = `What is ${num1} multiply by ${num2}?`;
const correctAns = num1 * num2;
formE1.addEventListener("submit", ()=>{
const userAns = inputE1.value
if(userAns == correctAns){
score++;
updateLocalStorage()
}else{
score--;
updateLocalStorage()
}
});
function updateLocalStorage(){
localStorage.setItem("score", JSON.stringify(score))
}