-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
92 lines (79 loc) · 2.61 KB
/
script.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
let count_you=0;
let count_comp=0;
const arr=[];
// paper0 rock1 scissor2
let paper =document.querySelector("#pic1");
let rock =document.querySelector("#pic2");
let scissor =document.querySelector("#pic3");
let Result2 =document.querySelector("#Result2");
let Result_You =document.querySelector("#Result_You");
let Result_comp =document.querySelector("#Result_comp");
paper.addEventListener("click",()=>{
arr[0]=0;
paper.style.height= "200px";
});
rock.addEventListener("click",()=>{
arr[0]=1;
});
scissor.addEventListener("click",()=>{
arr[0]=2;
});
Result2.addEventListener("click",()=>{
let random=Math.floor(Math.random()*3);
if(arr[0]==0){
if(random==0){
Result2.innerText="It was a draw. Try again";
Result2.style.backgroundColor="#FFFACD";
}
else if(random==1){
Result2.innerText="You won. Wanna try again";
Result2.style.backgroundColor="#008000";
count_you+=1;
Result_You.innerText=count_you;
}
else{
Result2.innerText="You lost. Give it a try again Champ";
Result2.style.backgroundColor="#ff0000";
count_comp+=1;
Result_comp.innerText=count_comp;
}
}
else if(arr[0]==1){
if(random==1){
Result2.innerText="It was a draw. Try again";
Result2.style.backgroundColor="#FFFACD";
}
else if(random==2){
Result2.innerText="You won. Wanna try again";
Result2.style.backgroundColor="#008000";
count_you+=1;
Result_You.innerText=count_you;
}
else{
Result2.innerText="You lost. Give it a try again Champ";
Result2.style.backgroundColor="#ff0000";
count_comp+=1;
Result_comp.innerText=count_comp;
}
}
else{
if(arr[0]==2){
if(random==2){
Result2.innerText="It was a draw. Try again";
Result2.style.backgroundColor="#FFFACD";
}
else if(random==0){
Result2.innerText="You won. Wanna try again";
Result2.style.backgroundColor="#008000";
count_you+=1;
Result_You.innerText=count_you;
}
else{
Result2.innerText="You lost. Give it a try again Champ";
Result2.style.backgroundColor="#ff0000";
count_comp+=1;
Result_comp.innerText=count_comp;
}
}
}
});