-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRPS.js
262 lines (209 loc) · 8.76 KB
/
RPS.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
let resetguy=document.querySelector("#resetbutton");
let startguy=document.querySelector("#startbutton");
let youcount=0;
let compcount=0;
mode="start";
const makemodestart=()=>{
mode="start"
}
const startingiwant=()=>{
if(mode=="start"){
// gets a number and converts in string for getting choice of computer.
let getanumber=(min,max)=>{
return Math.floor(Math.random()*max)+min
}
let winORlose=(c_choice,user_choice)=>{
if (c_choice === user_choice) {
return "That's a tie";
} else if (
(c_choice === "Rock" && user_choice === "Scissor") ||
(c_choice === "Paper" && user_choice === "Rock") ||
(c_choice === "Scissor" && user_choice === "Paper")
) {
return "Computer wins";
} else {
return "User wins";
}}
// computer choice
const compchoice=()=>{
let choice=["Rock","Paper","Scissor"];
let cnc=getanumber(0,3);
let choiceofcomp=choice[cnc]; //computer choice here
return choiceofcomp
}
// computer choice
const evaluatechoices=(choiceofuser,computerchoice)=>{
let y=winORlose(`${computerchoice}`,`${choiceofuser}`)
let userscoremeter=document.querySelector("#youinnerscoremeter")
let compscoremeter=document.querySelector("#compinnerscoremeter")
let userscore=document.querySelector("#youscore");
let compscore=document.querySelector("#compuscore");
if (y=="User wins"){
youcount += 1;
let elementhistoryouter=document.getElementById("history");
let newgif=document.createElement("div");
newgif.id="gifshower";
elementhistoryouter.appendChild(newgif);
if(youcount==1){
userscoremeter.style.width="70px";
userscore.innerText="1";
}
else if(youcount==2){
userscoremeter.style.width="140px";
userscore.innerText="2";
}
else if(youcount==3){
userscoremeter.style.width="210px";
userscore.innerText="3";
}
else if(youcount==4){
userscoremeter.style.width="280px";
userscore.innerText="4";
}
else if(youcount==5){
userscoremeter.style.width="388px";
userscore.innerText="5";
setTimeout(() => {
location.reload();
}, 2000);
}
}
else if (y=="Computer wins"){
compcount += 1;
if(compcount==1){
compscoremeter.style.width="70px";
compscore.innerText="1";
}
else if(compcount==2){
compscoremeter.style.width="140px";
compscore.innerText="2";
}
else if(compcount==3){
compscoremeter.style.width="210px";
compscore.innerText="3";
}
else if(compcount==4){
compscoremeter.style.width="280px";
compscore.innerText="4";
}
else if(compcount==5){
compscoremeter.style.width="388px";
compscore.innerText="5";
setTimeout(() => {
location.reload();
}, 2000);
}
}
const clearingforcompdecor=(sfbkj)=>{setTimeout(() => {
clearInterval(operation);
rcdr=document.getElementById(`${sfbkj}`)
rcdr.style.borderWidth="0px";
},1500);}
let operation=setInterval(()=>{
if(computerchoice=="Rock"){
let rcdr=document.getElementById("rockforcomputer");
rcdr.style.borderWidth="40px";
rcdr.style.borderColor="white";
clearingforcompdecor("rockforcomputer");
}
else if(computerchoice=="Paper"){
let rcdr=document.getElementById("paperforcomputer");
rcdr.style.borderWidth="40px";
rcdr.style.borderColor="white";
clearingforcompdecor("paperforcomputer");
}
else if(computerchoice=="Scissor"){
let rcdr=document.getElementById("scissorforcomputer");
rcdr.style.borderWidth="40px";
rcdr.style.borderColor="white";
clearingforcompdecor("scissorforcomputer");
}
},1500)
if (computerchoice=="Paper"|| computerchoice=="Rock" || computerchoice=="Scissor"){
clearingforcompdecor()
}
// history deco
let operationresult=setInterval(()=>{
let elementhistoryouter=document.getElementById("history");
let newelement=document.createElement("h2");
newelement.innerText=y;
// elementhistoryouter.style.al="center";
// newelement.style.marginLeft="90px";
newelement.style.marginTop="8px";
newelement.style.marginLeft="10px";
newelement.style.fontFamily="Aerial"
newelement.style.color="black";
if(newelement.innerText=="User wins"){
newelement.style.backgroundColor="limegreen"
}
else if(newelement.innerText=="Computer wins"){
// newelement.style.color="red";
newelement.style.backgroundColor="red"
}
else{
// newelement.style.color="orange";
newelement.style.backgroundColor="yellow"
}
elementhistoryouter.append(newelement);
},1000)
setTimeout(() => {
clearInterval(operationresult);
},1500);
// adding functionaly to choosy divs
// user
}
// user choice
const userchoice=()=>{
let Rockcontainerforyou=document.querySelector("#choosycontainerofyourock");
let Papercontainerforyou=document.querySelector("#choosycontainerofyoupaper");
let Scissorcontainerforyou=document.querySelector("#choosycontainerofyouscissor");
Rockcontainerforyou.addEventListener("click",()=>{
let computerchoiceis=compchoice();
let ucdr=document.getElementById("rockforyou");
ucdr.style.borderWidth="40px";
ucdr.style.borderColor="white";
remdivuserdecor=()=>{
setTimeout(()=>{
ucdr.style.borderWidth="0px";
},1500)}
remdivuserdecor()
evaluatechoices("Rock",`${computerchoiceis}`);
});
Papercontainerforyou.addEventListener("click",()=>{
let computerchoiceis=compchoice();
let ucdr=document.getElementById("paperforyou");
ucdr.style.borderWidth="40px";
ucdr.style.borderColor="white";
remdivuserdecor=()=>{
setTimeout(()=>{
let ucdr=document.getElementById("paperforyou");
ucdr.style.borderWidth="0px";
},1500)}
remdivuserdecor()
evaluatechoices("Paper",`${computerchoiceis}`);
});
Scissorcontainerforyou.addEventListener("click",()=>{
let computerchoiceis=compchoice();
let ucdr=document.getElementById("scissorforyou");
ucdr.style.borderWidth="40px";
ucdr.style.borderColor="white";
remdivuserdecor=()=>{
setTimeout(()=>{
ucdr.style.borderWidth="0px";
},1500)}
remdivuserdecor()
evaluatechoices("Scissor",`${computerchoiceis}`);
});
}
userchoice();
}
// starting i want ending }
}
// calls that startingiwant function to get started.
startguy.addEventListener("click",()=>{
makemodestart();
startingiwant();
})
resetguy.addEventListener("click",()=>{
location.reload();
})