forked from rocketacademy/basics-scissors-paper-stone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
225 lines (220 loc) · 7.05 KB
/
Copy pathscript.js
File metadata and controls
225 lines (220 loc) · 7.05 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
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
var GameStart = "Please input your name to start";
console.log(GameStart);
var Name = "";
var UserWinCounter = 0;
var ComputerWinCounter = 0;
var DrawCounter = 0;
var main = function (input) {
var SCISSORS = "scissors";
var PAPER = "paper";
var STONE = "stone";
var reversedSCISSORS = "reversed scissors";
var reversedPAPER = "reversed paper";
var reversedSTONE = "reversed stone";
// var CommputerObject = randomObjectByComputer();
var myOutputValue =
"Invalid input. Please enter 'scissors', 'paper', 'stone', 'reversed scissors', 'reversed paper' or 'reversed stone' to start the game.";
// to get user to input name at the start before game starts
if (GameStart == "Please input your name to start") {
Name = input;
GameStart = "Let's now play scissors-paper-stone!";
console.log(GameStart);
myOutputValue =
"Hello " +
Name +
"! Welcome to the scissors-paper-stone game. Please enter 'scissors', 'paper', 'stone', 'reversed scissors', 'reversed paper' or 'reversed stone' to start the game.";
} else if ((GameStart = "Let's now play scissors-paper-stone!")) {
console.log(GameStart);
var CommputerObject = randomObjectByComputer();
}
// scissors and scissors draw condition
if (
(input == SCISSORS && CommputerObject == SCISSORS) ||
(input == reversedSCISSORS && CommputerObject == SCISSORS)
) {
DrawCounter = DrawCounter + 1;
console.log("computer choice");
console.log(CommputerObject);
console.log("counting number of draws");
console.log(DrawCounter);
myOutputValue =
Name +
", you chose " +
input +
" ✂️.<br><br> Computer chose scissors ✂️. <br><br> It's a draw. <br><br> You have drawn " +
DrawCounter +
" times! Try again!";
}
// lose condition when computer plays scissors
// scissors beats paper
// scissors beats reversed stone
if (
(input == PAPER && CommputerObject == SCISSORS) ||
(input == reversedSTONE && CommputerObject == SCISSORS)
) {
ComputerWinCounter = ComputerWinCounter + 1;
console.log("computer choice");
console.log(CommputerObject);
console.log("counting computer wins");
console.log(ComputerWinCounter);
myOutputValue =
Name +
", you chose " +
input +
" 🗒. <br><br> Computer chose scissors ✂️. <br><br> You lost.<br><br> You have won " +
UserWinCounter +
" times so far. Keep going!";
}
// win condition when computer plays scissors
// stone beats scissors
// reversed paper beats scissors
if (
(input == STONE && CommputerObject == SCISSORS) ||
(input == reversedPAPER && CommputerObject == SCISSORS)
) {
UserWinCounter = UserWinCounter + 1;
console.log("computer choice");
console.log(CommputerObject);
console.log("counting user wins");
console.log(UserWinCounter);
myOutputValue =
Name +
", you chose " +
input +
" 💎. <br><br> Computer chose scissors ✂️.<br><br> You won! <br><br> You have won " +
UserWinCounter +
" times so far! Good job!";
}
// win condition when computer plays paper
// scissors bears paper
// reversed stone beats paper
if (
(input == SCISSORS && CommputerObject == PAPER) ||
(input == reversedSTONE && CommputerObject == PAPER)
) {
UserWinCounter = UserWinCounter + 1;
console.log("computer choice");
console.log(CommputerObject);
console.log("counting user wins");
console.log(UserWinCounter);
myOutputValue =
Name +
", you chose " +
input +
" ✂️.<br><br> Computer chose paper 🗒.<br><br> You won! <br><br> You have won " +
UserWinCounter +
" times so far! Good job!";
}
// paper and paper draw condition
if (
(input == PAPER && CommputerObject == PAPER) ||
(input == reversedPAPER && CommputerObject == PAPER)
) {
DrawCounter = DrawCounter + 1;
console.log("computer choice");
console.log(CommputerObject);
console.log("counting number of draws");
console.log(DrawCounter);
myOutputValue =
Name +
", you chose " +
input +
" 🗒.<br><br> Computer chose paper 🗒.<br><br> It's a draw. <br><br> You have drawn " +
DrawCounter +
" times! Try again!";
}
// lose condition when computer plays paper
// paper beats stone
// paper beats reversed scissors
if (
(input == STONE && CommputerObject == PAPER) ||
(input == reversedSCISSORS && CommputerObject == PAPER)
) {
ComputerWinCounter = ComputerWinCounter + 1;
console.log("computer choice");
console.log(CommputerObject);
console.log("counting computer wins");
console.log(ComputerWinCounter);
myOutputValue =
Name +
", you chose " +
input +
" 💎.<br><br> Computer chose paper 🗒. <br><br>You lost. <br><br> You have won " +
UserWinCounter +
" times so far. Keep going!";
}
// lose condition when computer plays stone
// stone beats scissors
// stone beats reversed paper
if (
(input == SCISSORS && CommputerObject == STONE) ||
(input == reversedPAPER && CommputerObject == STONE)
) {
ComputerWinCounter = ComputerWinCounter + 1;
console.log("computer choice");
console.log(CommputerObject);
console.log("counting computer wins");
console.log(ComputerWinCounter);
myOutputValue =
Name +
", you chose " +
input +
" ✂️.<br><br> Computer chose stone 💎.<br><br> You lost. <br><br> You have won " +
UserWinCounter +
" times so far. Keep going!";
}
// win condition when computer plays stone
// paper beats stone
// reversed scissors beats stone
if (
(input == PAPER && CommputerObject == STONE) ||
(input == reversedSCISSORS && CommputerObject == STONE)
) {
UserWinCounter = UserWinCounter + 1;
console.log("computer choice");
console.log(CommputerObject);
console.log("counting user wins");
console.log(UserWinCounter);
myOutputValue =
Name +
", you chose " +
input +
" 🗒.<br><br> Computer chose stone 💎.<br><br> You won! <br><br> You have won " +
UserWinCounter +
" times so far! Good job!";
}
// stone and stone draw condition
if (
(input == STONE && CommputerObject == STONE) ||
(input == reversedSTONE) & (CommputerObject == STONE)
) {
DrawCounter = DrawCounter + 1;
console.log("computer choice");
console.log(CommputerObject);
console.log("counting number of draws");
console.log(DrawCounter);
myOutputValue =
Name +
", you chose " +
input +
" 💎.<br><br> Computer chose stone 💎.<br><br> It's a draw. <br><br> You have drawn " +
DrawCounter +
" times! Try again!";
}
return myOutputValue;
};
// assigning values 0,1,2 to the object computer will draw
var randomObjectByComputer = function () {
var SCISSORS = "scissors";
var PAPER = "paper";
var STONE = "stone";
var randomDecimal = Math.random() * 3;
var randomNum = Math.floor(randomDecimal);
if (randomNum == 0) {
return SCISSORS;
}
if (randomNum == 1) {
return PAPER;
}
return STONE;
};