-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.js
67 lines (49 loc) · 1.65 KB
/
add.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
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
const option1 = document.getElementById("option1"),
option2 = document.getElementById("option2"),
option3 = document.getElementById("option3");
var myAudioWrong = document.getElementById("myAudioWrong");
var myAudioRight = document.getElementById("myAudioRight")
var answer = 0;
function generate_equation(){
var num1 = Math.floor(Math.random() * 13),
num2 = Math.floor(Math.random() * 13),
dummyAnswer1 = Math.floor(Math.random() * 10),
dummyAnswer2 = Math.floor(Math.random() * 10),
allAnswers = [],
switchAnswers = [];
answer = eval(num1 + num2);
document.getElementById("num1").innerHTML = num1;
document.getElementById("num2").innerHTML = num2;
allAnswers = [answer, dummyAnswer1, dummyAnswer2];
for (i = allAnswers.length; i--;){
switchAnswers.push(allAnswers.splice(Math.floor(Math.random() * (i + 1)), 1)[0]);
};
option1.innerHTML = switchAnswers[0];
option2.innerHTML = switchAnswers[1];
option3.innerHTML = switchAnswers[2];
};
option1.addEventListener("click", function(){
if(option1.innerHTML == answer){
myAudioRight.play();
generate_equation();
}else{
myAudioWrong.play();
}
});
option2.addEventListener("click", function(){
if(option2.innerHTML == answer){
myAudioRight.play();
generate_equation();
}else{
myAudioWrong.play();
}
});
option3.addEventListener("click", function(){
if(option3.innerHTML == answer){
myAudioRight.play();
generate_equation();
}else{
myAudioWrong.play();
}
});
generate_equation()