-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
69 lines (55 loc) · 2.07 KB
/
Copy pathscript.js
File metadata and controls
69 lines (55 loc) · 2.07 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
let img = [
"img/one.svg",
"img/two.svg",
"img/three.svg",
"img/four.svg",
"img/five.svg",
"img/six.svg",
];
let dice1 = document.querySelector("img");
let roll1 = document.getElementById("P1");
let roll2 = document.getElementById("P2");
function btn1(p1) {
roll2.disabled = false;
let dieonevalue = Math.floor(Math.random() * 6);
document.getElementById("P2").style.backgroundColor = "green"
document.querySelector("#die-1").setAttribute("src", img[dieonevalue]);
document.querySelector("#span1").innerHTML = (dieonevalue+1) + parseInt(document.querySelector("#span1").innerHTML);
if (p1 === "p1") {
roll1.disabled = true ;
document.getElementById("h1").innerHTML = "Player-2 To Play"
document.getElementById("P1").style.backgroundColor = "grey"
}
var val1 = parseInt(document.querySelector("#span1").innerHTML);
if(val1 >= 30){
document.getElementById("wins").innerHTML= "Player-1 is winning";
roll1.disabled = true;
document.getElementById("P1").style.backgroundColor = "grey"
roll2.disabled = true;
document.getElementById("P2").style.backgroundColor = "grey"
}
}
let dice2 = document.querySelector("img");
function btn2(p2) {
roll1.disabled = false;
let dietwovalue = Math.floor(Math.random() * 6);
document.getElementById("P1").style.backgroundColor = "green"
document.querySelector("#die-1").setAttribute("src", img[dietwovalue]);
document.querySelector("#span2").innerHTML = (dietwovalue + 1)+parseInt(document.querySelector("#span2").innerHTML);
if (p2 === "p2") {
roll2.disabled = true;
document.getElementById("h1").innerHTML = "Player-1 To Play";
document.getElementById("P2").style.backgroundColor = "grey"
}
var val2 = parseInt(document.querySelector("#span2").innerHTML)
if(val2 >= 30){
document.getElementById("wins").innerHTML= "Player-2 is winning";
roll1.disabled = true;
document.getElementById("P1").style.backgroundColor = "grey"
roll2.disabled = true;
document.getElementById("P2").style.backgroundColor = "grey"
}
}
function reset(){
location.reload();
}