-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
50 lines (40 loc) · 1.41 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
var button1=document.getElementById("bp1");
var button2=document.getElementById("bp2");
var score1=document.getElementsByClassName("score")[0];
var score2=document.getElementsByClassName("score")[1];
var win=parseInt(prompt("What is the winning score?"));
var toWin1=document.getElementById("towin1");
var toWin2=document.getElementById("towin2");
var toWin=document.getElementById("winscore");
var scorebox=document.getElementsByClassName("container")[0];
var winner=document.getElementById("winner");
var gameover=false;
toWin1.textContent=toWin2.textContent=toWin.textContent=win;
button1.addEventListener("click",function(){
if(gameover==false){
var temp=parseInt(score1.textContent);
console.log(temp);
temp=temp+1;
score1.textContent=temp;
toWin1.textContent=parseInt(toWin1.textContent)-1;
}
if(toWin1.textContent==0){
scorebox.style.display='none';
gameover=true;
winner.textContent="Player 1";
}
});
button2.addEventListener("click",function(){
if(gameover==false){
var temp=parseInt(score2.textContent);
console.log(toWin2.textContent==win);
temp=temp+1;
score2.textContent=temp;
toWin2.textContent=parseInt(toWin2.textContent)-1;
}
if(toWin2.textContent==0){
scorebox.style.display='none';
gameover=true;
winner.textContent="Player 1";
}
});