-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.js
58 lines (52 loc) · 1.87 KB
/
project.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
const p1Display= document.querySelector('#p1Display');
const p2Display= document.querySelector('#p2Display');
const resetButton=document.querySelector('#Reset');
const p1button=document.querySelector('#button1');
const p2button=document.querySelector('#button2');
const winningscoreSelect=document.querySelector('#playTo');
let p1Score=0;
let p2Score=0;
let isGameOver=false;
let winningScore=3;
alert("Welcome to Score Board.....");
setTimeout(()=>{alert("Now Keep Your Score Here....")},300);
winningscoreSelect.addEventListener('change',function(){
winningScore=parseInt(this.value);
reset();
})
p1button.addEventListener('click',function(){
if(!isGameOver){
p1Score+=1;
if(p1Score===winningScore){
isGameOver=true;
p1Display.classList.add('winner');
p2Display.classList.add('loser');
setTimeout(()=>{alert("Congrats Player A wins!!")},500);
setTimeout(()=>{alert("Hey Press the Reset key to start recording again or click to submit.")},1000)
}
p1Display.textContent=p1Score;
}
})
p2button.addEventListener('click',function(){
if(!isGameOver){
p2Score+=1;
if(p2Score===winningScore){
isGameOver=true;
p2Display.classList.add('winner');
p1Display.classList.add('loser');
setTimeout(()=>{alert("Congrats Player B wins!!")},500);
setTimeout(()=>{alert("Hey Press the Reset key to start recording again or click to submit.")},1000)
}
p2Display.textContent=p2Score;
}
})
resetButton.addEventListener('click',reset)
function reset(){
isGameOver=false;
p1Score=0;
p2Score=0;
p1Display.textContent=0;
p2Display.textContent=0;
p1Display.classList.remove('winner','loser');
p2Display.classList.remove('winner','loser');
}