-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyscript.js
38 lines (33 loc) · 1.57 KB
/
myscript.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
var array = ["","green", "gray","red","white","blue","yellow"];
var score = 1;
var vite = 3;
window.onload = () => {
const threeLifes = (new Array(vite)).fill(null).map(x => "<li><img src='icons8-heart-64.png'></li>").join("");
document.querySelector(".lifeBar").innerHTML = threeLifes;
const spawn = setInterval(function spawnBall() {
if ( document.hasFocus() ) {
const div = document.createElement("div") ;
document.body.appendChild( div ) ;
div.className = "ball rounded-circle" ;
div.style.top = "100%";
div.style.left = ( 90 * Math.random() ) + "%" ;
div.style.backgroundColor = array[Math.floor((Math.random() * 6) + 1)];
div.addEventListener("click", function(ball){
ball.target.parentElement.removeChild(ball.target);
document.getElementById("score").innerHTML=score;
score++;
if(score > 20){spawnBall()}
else if(count > 30){ spawnBall(),spawnBall()}
});
div.addEventListener("animationend", function(ball){
ball.target.parentElement.removeChild(ball.target);
vite--;
document.querySelector("li").remove();
if(vite<1){
clearInterval(spawn);
document.body.innerHTML = "<div class='gg'><h1>Game Over</h1><h2>"+score+"</h2><button onClick='window.location.reload()'>Retry</button></div>";
}
});
}
}, 900);
}