-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
54 lines (50 loc) · 1.68 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var number = Math.floor(Math.random() * 8 + 2);
var start = 0;
function generateBubbles() {
let bubbles = "";
document.querySelector("#playareabubble").style.opacity = 1;
for (let i = 0; i < 1; i++) {
bubbles += `<div id="bubble">${number}</div>`;
}
document.querySelector("#playareabubble").innerHTML = bubbles;
}
var posi = 0;
var score = 0;
function insideBubble() {
if (number > 1) {
number = number - 1;
document.querySelector("#bubble").innerHTML = number;
} else {
document.querySelector("#playareabubble").style.opacity = 0;
generateBubbles();
score = Number(document.querySelector("#box1").innerHTML) + 10;
document.querySelector("#box1").innerHTML = score;
number = Math.floor(Math.random() * 8 + 2);
document.querySelector("#bubble").innerHTML = number;
document.querySelector("#playareabubble");
}
document.querySelector("#finalScore").innerHTML = score;
}
function startgame() {
var start = document.querySelector("#startpage");
start.style.display = "none";
generateBubbles();
var ypos = 0;
var xpos = [100, 180, 35, 250, 134];
setInterval(() => {
document.querySelector("#playareabubble").style.top = `${ypos}%`;
document.querySelector("#playareabubble").style.left = `${
xpos[Math.floor(Math.random() * 5)]
}px`;
ypos = ypos + 5;
if (ypos > 92) {
document.querySelector("#box3").innerHTML =
document.querySelector("#box3").innerHTML - 1;
var lives = document.querySelector("#box3").innerHTML;
if (lives == 0) {
document.getElementById("playground").style.display = "none";
}
ypos = 0;
}
}, 600);
}