-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
80 lines (70 loc) · 2.46 KB
/
Copy pathscript.js
File metadata and controls
80 lines (70 loc) · 2.46 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
window.alert("Welcome to Adi's Bubble Game");
var instructions = `Instructions: You have to press the bubble corresponding to the number being displayed beside 'Hit', note that pressing the wrong bubble will decrease your Score.`;
window.alert(instructions);
var timer = prompt("How long do you want to play this game (in seconds)");
var pointTimer=timer;
timer++;
function MakeBubble(){
var drop="";
for (var i=1; i<=102; i++){
drop += `<div class="bubble">${Math.round(Math.random()*10)}</div>`;
}
document.querySelector("#panelbtm").innerHTML=drop;
}
MakeBubble();
function Timeout(){
var timeInt = setInterval(function(){
timer-=1;
if(timer>=0){
document.querySelector("#time").textContent=timer;
}
else{
clearInterval(timeInt);
if(score>=pointTimer*6){
document.querySelector("#panelbtm").innerHTML= `<center><h1>Outstanding Champ!<br>Your Score was ${score} 🎉</center></h1>`;
}
else if(score>=pointTimer*5){
document.querySelector("#panelbtm").innerHTML= `<center><h1>Well Played Champ!<br>Your Score was ${score} 🎉</center></h1>`;
}
else if(score>=pointTimer*3){
document.querySelector("#panelbtm").innerHTML= `<center><h1>A Great Game!<br>Your Score was ${score} 🎉</center></h1>`;
}
else if(score>=pointTimer*2){
document.querySelector("#panelbtm").innerHTML= `<center><h1>Decent Play!<br>Your Score was ${score} 🎉</center></h1>`;
}
else {
document.querySelector("#panelbtm").innerHTML= `<center><h1>Can do better!<br>Your Score was ${score} 🎉</center></h1>`;
}
}
}, 1000);
}
Timeout();
var hitnum=0;
function NewHit(){
hitnum=Math.round(Math.random()*10);
document.querySelector("#hitval").textContent=hitnum;
}
NewHit();
var score=0;
function IncreaseScore(){
score+=10;
document.querySelector("#scoreval").textContent=score;
}
function DecreaseScore(){
score-=10;
document.querySelector("#scoreval").textContent=score;
}
document.querySelector("#panelbtm").
addEventListener('click', function(dets){
var clickednum = (Number(dets.target.textContent));
if(hitnum==clickednum){
IncreaseScore();
NewHit();
MakeBubble();
}
else if(clickednum!=hitnum && clickednum<=10){
DecreaseScore();
NewHit();
MakeBubble();
}
})