-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
73 lines (66 loc) · 2.81 KB
/
app.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
68
69
70
71
72
73
const score = document.querySelector(".score");
const number = document.querySelector(".number");
const btn = document.querySelectorAll(".btn");
const small = document.querySelector(".small > .btn");
const big = document.querySelector(".big > .btn");
var point = 0;
function randomNumber() {
random = Math.floor(Math.random() * 10);
return random;
}
window.addEventListener('load', () => {
number.innerText = randomNumber();
btn.forEach(buton => {
buton.addEventListener('click', () => {
let oldnumber = number.innerText;
let newnumber = randomNumber();
switch (buton.innerText) {
case 'Small':
if (oldnumber > newnumber) {
point++;
score.innerText = point;
number.innerText = newnumber;
console.log("Old Number: " + oldnumber);
console.log("New Number: " + newnumber);
console.log("You Win!");
console.log("Point: " + point);
console.log("------------------------------------");
} else {
point--;
score.innerText = point;
number.innerText = newnumber;
console.log("Old Number: " + oldnumber);
console.log("New Number: " + newnumber);
console.log("You Lose!");
console.log("Point: " + point);
console.log("------------------------------------");
}
break;
case 'Big':
if (oldnumber < newnumber) {
point++;
score.innerText = point;
number.innerText = newnumber;
console.log("Old Number: " + oldnumber);
console.log("New Number: " + newnumber);
console.log("You Win!");
console.log("Point: " + point);
console.log("------------------------------------");
} else {
point--;
score.innerText = point;
number.innerText = newnumber;
console.log("Old Number: " + oldnumber);
console.log("New Number: " + newnumber);
console.log("You Lose!");
console.log("Point: " + point);
console.log("------------------------------------");
}
break;
default:
console.log('error');
break;
}
});
});
});