-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
51 lines (30 loc) · 993 Bytes
/
main.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
//Player 1
// Generate Random Number
var random1 = Math.floor(Math.random()*6)+1;
// Get The Element
var dice1= document.querySelector('.img1');
// Path For THe Image
var select1 = "/images" + "/dice" + random1 + ".png";
// setAttribute is Property by using this you change the src path of image
dice1.setAttribute("src",select1);
// Same For Player 2
// Player 2
// Generate Random Number
var random2 = Math.floor(Math.random()*6)+1;
// Get The Element
var dice2= document.querySelector('.img2');
// Path For THe Image
var select2 = "/images" + "/dice" + random2 + ".png";
// setAttribute is Property by using this you change the src path of image
dice2.setAttribute("src",select2);
// Games Rules
if(random1>random2){
document.querySelector('h1').textContent = "Player 1 Won The Match";
}
else if(random1 < random2)
{
document.querySelector('h1').textContent = "Player 2 Won The Match"
}
else{
document.querySelector('h1').textContent = "Match Draw";
}