-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
61 lines (52 loc) · 1.75 KB
/
app.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
59
60
61
const btn1 = document.getElementById("btnPlayer1");
const btn2 = document.getElementById("btnPlayer2");
const btnReset = document.getElementById("btnReset");
const spanP1 = document.querySelector(".spanPlayer1");
const spanP2 = document.querySelector(".spanPlayer2");
const inputScore = document.getElementById("winScore");
const image = document.querySelector(".image");
const text = document.querySelector("h1");
inputScore.focus();
btn1.addEventListener("click", (e) => {
e.preventDefault();
if (inputScore.value > 10 || inputScore.value < 1) {
alert("Score to Win: must be between 1 and 10");
inputScore.value = "5";
return;
}
spanP1.innerHTML++;
if (spanP1.innerHTML == inputScore.value) {
image.style.backgroundImage = "url(./img/wingiphy.gif)";
image.style.width = "35em";
text.innerHTML = "WINNER : PLAYER 1 !";
text.style.color = "green";
spanP1.style.color = "green";
spanP2.style.color = "red";
btn1.style.opacity = "0.5";
btn2.style.opacity = "0.5";
btn1.disabled = true;
btn2.disabled = true;
}
});
btn2.addEventListener("click", (e) => {
e.preventDefault();
if (inputScore.value > 10 || inputScore.value < 1) {
alert("Score to Win: must be between 1 and 10");
inputScore.value = "5";
return;
}
spanP2.innerHTML++;
if (spanP2.innerHTML == inputScore.value) {
image.style.backgroundImage = "url(./img/wingiphy.gif)";
image.style.width = "35em";
text.innerHTML = "WINNER : PLAYER 2 !";
text.style.color = "green";
spanP1.style.color = "red";
spanP2.style.color = "green";
btn1.style.opacity = "0.5";
btn2.style.opacity = "0.5";
btn1.disabled = true;
btn2.disabled = true;
}
});
btnReset.addEventListener("click", ()=>{location.reload();});