-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (48 loc) · 1.97 KB
/
index.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
let randomNumber1=Math.floor(Math.random()*6)+1;
console.log(randomNumber1);
let b= document.querySelector("img").getAttribute("src");
switch(randomNumber1){
case 1:
document.querySelector("img").setAttribute("src","images/dice1.png")
break;
case 2:
document.querySelector("img").setAttribute("src","images/dice2.png")
break;
case 3:
document.querySelector("img").setAttribute("src","images/dice3.png")
break;
case 4:
document.querySelector("img").setAttribute("src","images/dice4.png")
break;
case 5:
document.querySelector("img").setAttribute("src","images/dice5.png")
break;
case 6:
document.querySelector("img").setAttribute("src","images/dice6.png")
break;
}
let randomNumber2=Math.floor(Math.random()*6)+1;
let dices="images/dice"+randomNumber2+".png";
let solution= document.querySelectorAll("img")[1];
solution.setAttribute("src", dices);
/*if(randomNumber2===1){
document.querySelector(".img2").setAttribute("src", "images/dice1.png");
}else if(randomNumber2===2){
document.querySelector(".img2").setAttribute("src", "images/dice2.png");
}else if(randomNumber2===3){
document.querySelector(".img2").setAttribute("src", "images/dice3.png");
}else if(randomNumber2===4){
document.querySelector(".img2").setAttribute("src", "images/dice4.png");
}else if(randomNumber2===5){
document.querySelector(".img2").setAttribute("src", "images/dice5.png");
}else if(randomNumber2===6){
document.querySelector(".img2").setAttribute("src", "images/dice6.png");
}*/
//let result= (randomNumber1 > randomNumber2) ? document.querySelector("h1").innerHTML="Player 1 Wins!" : document.querySelector("h1").innerHTML="Player 2 Wins!"
if(randomNumber1 > randomNumber2){
document.querySelector("h1").innerHTML="Player 1 Wins!" ;
}else if (randomNumber1 < randomNumber2){
document.querySelector("h1").innerHTML="Player 2 Wins!" ;
}else if(randomNumber2===randomNumber1){
document.querySelector("h1").innerHTML="Draw" ;
}