-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaths.js
More file actions
81 lines (61 loc) · 2.28 KB
/
maths.js
File metadata and controls
81 lines (61 loc) · 2.28 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var answer;
var score = 0;
var backgroundImages = [];
function nextQuestion(calc) {
if (calc == 'add'){
const n1 = Math.floor(Math.random() * 50);
document.getElementById('n1').innerHTML = n1;
const n2 = Math.ceil(Math.random() * 50);
document.getElementById('n2').innerHTML = n2;
answer = n1 + n2;
} else if (calc == 'sub') {
const n1 = Math.floor(Math.random() * 100);
const n2 = Math.ceil(Math.random() * 100);
if (n1 > n2) {
document.getElementById('n1').innerHTML = n1;
document.getElementById('n2').innerHTML = n2;
answer = n1 - n2;
} else {
document.getElementById('n1').innerHTML = n2;
document.getElementById('n2').innerHTML = n1;
answer = n2 - n1;
}
} else {
const n1 = Math.floor(Math.random() * 10);
document.getElementById('n1').innerHTML = n1;
const n2 = Math.ceil(Math.random() * 10);
document.getElementById('n2').innerHTML = n2;
answer = n1 * n2;
}
}
function checkAnswer() {
const prediction = predictImage();
console.log(prediction);
var predictAnswer = 0;
for (let i = 0; i < prediction.length; i++) {
predictAnswer += (prediction[i]*(10**(prediction.length - i - 1)));
console.log(`${prediction[i]}, ${predictAnswer}`);
}
if (predictAnswer == answer){
score += 1;
console.log(`Correct, score: ${score}`);
if (score <= 6){
backgroundImages.push(`url('images/background${score}.svg')`);
document.body.style.backgroundImage = backgroundImages;
} else {
alert("Congrats kiddo!!");
score = 0;
backgroundImages = [];
document.body.style.backgroundImage = backgroundImages;
}
nextQuestion();
} else{
if (score != 0 ){
score -= 1;
backgroundImages.pop();
document.body.style.backgroundImage = backgroundImages;
}
console.log(`False, score: ${score}`);
alert('Oops! Check your calculation and try writing the number neater next time');
}
}