-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.js
More file actions
184 lines (173 loc) · 4.68 KB
/
main.js
File metadata and controls
184 lines (173 loc) · 4.68 KB
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
let cscore=0
let pscore=0
let selection=null
let count=0
let modal = document.getElementById('myModal');
function randomselect(arr){
var rand = arr[Math.floor(Math.random() * arr.length)];
return rand
}
function rock(){
selection='rock'
game()
count+=1
if(count===5){
compare(pscore,cscore)
modal.style.display = "block";
}
}
function paper(){
selection='paper'
game()
count+=1
if(count===5){
compare(pscore,cscore)
modal.style.display = "block";
}
}
function scissors(){
selection='scissors'
game()
count+=1
if(count===5){
compare(pscore,cscore)
modal.style.display = "block";
}
}
function computerPlay(playerSelection){
sel=selection
let arr=['rock','paper','scissors']
let computerSelection=randomselect(arr)
if(computerSelection===playerSelection){
return ['T','-1']
}
else{
if(computerSelection==='rock'){
if(sel==='paper'){
return ['W','1']
}
else if(sel==='scissors'){
return ['L','0']
}
}
else if(computerSelection==='paper'){
if(sel==='rock'){
return ['L','0']
}
else if(sel==='scissors'){
return ['W','1']
}
}
else if(computerSelection==='scissors'){
if(sel==='rock'){
return ['W','1']
}
else if(sel==='paper'){
return ['L','0']
}
}
}
}
function compare(pscore,cscore){
if(pscore>cscore){
document.getElementById('mytext').innerHTML='You win!'
}
else if(cscore>pscore){
document.getElementById('mytext').innerHTML='You lose!'
}
else{
document.getElementById('mytext').innerHTML='It\'s a tie!'
}
}
function refresh(){
window.location.reload();
}
function game(){
console.log(selection)
results=computerPlay(selection)
if(results[1]==='-1'){
cscore+=1
pscore+=1
if(count==0){
//round1
document.getElementById('R1Y').innerHTML='T'
document.getElementById('R1C').innerHTML='T'
}
else if(count==1){
//round 2
document.getElementById('R2Y').innerHTML='T'
document.getElementById('R2C').innerHTML='T'
}
else if(count==2){
//round3
document.getElementById('R3Y').innerHTML='T'
document.getElementById('R3C').innerHTML='T'
}
else if(count==3){
//round4
document.getElementById('R4Y').innerHTML='T'
document.getElementById('R4C').innerHTML='T'
}
else if(count==4){
//round5
document.getElementById('R5Y').innerHTML='T'
document.getElementById('R5C').innerHTML='T'
}
}
else if(results[1]==='0'){
cscore+=1
if(count==0){
//round1
document.getElementById('R1Y').innerHTML='L'
document.getElementById('R1C').innerHTML='W'
}
else if(count==1){
//round 2
document.getElementById('R2Y').innerHTML='L'
document.getElementById('R2C').innerHTML='W'
}
else if(count==2){
//round3
document.getElementById('R3Y').innerHTML='L'
document.getElementById('R3C').innerHTML='W'
}
else if(count==3){
//round4
document.getElementById('R4Y').innerHTML='L'
document.getElementById('R4C').innerHTML='W'
}
else if(count==4){
//round5
document.getElementById('R5Y').innerHTML='L'
document.getElementById('R5C').innerHTML='W'
}
}
else if(results[1]==='1'){
pscore+=1
if(count==0){
//round1
document.getElementById('R1Y').innerHTML='W'
document.getElementById('R1C').innerHTML='L'
}
else if(count==1){
//round 2
document.getElementById('R2Y').innerHTML='W'
document.getElementById('R2C').innerHTML='L'
}
else if(count==2){
//round3
document.getElementById('R3Y').innerHTML='W'
document.getElementById('R3C').innerHTML='L'
}
else if(count==3){
//round4
document.getElementById('R4Y').innerHTML='W'
document.getElementById('R4C').innerHTML='L'
}
else if(count==4){
//round5
document.getElementById('R5Y').innerHTML='W'
document.getElementById('R5C').innerHTML='L'
}
}
}