-
Notifications
You must be signed in to change notification settings - Fork 0
/
dice.js
59 lines (50 loc) · 1.6 KB
/
dice.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
let random_number1=Math.floor((Math.random()*6))+1
console.log(random_number1)
let random_number2=Math.floor((Math.random()*6))+1
console.log(random_number2)
if(random_number1>random_number2){
document.querySelector("h1").innerText="Player 1 won"
}
else{
document.querySelector("h1").innerText="Player 2 won"
}
if(random_number1===1){
document.querySelector(".img1").setAttribute("src", "dice1.png")
}
else if(random_number1===2){
document.querySelector(".img1").setAttribute("src", "dice2.png")
}
else if(random_number1===3){
document.querySelector(".img1").setAttribute("src", "dice3.png")
}
else if(random_number1===4){
document.querySelector(".img1").setAttribute("src", "dice4.png")
}
else if(random_number1===5){
document.querySelector(".img1").setAttribute("src", "dice5.png")
}
else{
document.querySelector(".img1").setAttribute("src", "dice6.png")
}
if(random_number2===1){
document.querySelector(".img2").setAttribute("src", "dice1.png")
}
else if(random_number2===2){
document.querySelector(".img2").setAttribute("src", "dice2.png")
}
else if(random_number2===3){
document.querySelector(".img2").setAttribute("src", "dice3.png")
}
else if(random_number2===4){
document.querySelector(".img2").setAttribute("src", "dice4.png")
}
else if(random_number2===5){
document.querySelector(".img2").setAttribute("src", "dice5.png")
}
else{
document.querySelector(".img2").setAttribute("src", "dice6.png")
}
random_number1=Math.floor((Math.random()*6))+1
console.log(random_number1)
random_number2=Math.floor((Math.random()*6))+1
console.log(random_number2)