-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.js
49 lines (38 loc) · 1.06 KB
/
Game.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
// Game of snake, water & gun. The game should ask you to enter S, W or G. The computer will randomly generate S,W or G and declare win or loss using alert.
// S, W, G
// s w = s
// s g = g
// g w = w
let arr = ['s', 'w', 'g']
let score = 0;
let runAgain = true;
const check = (char, random) => {
('s' > 'w' && 's' < 'g' && 'g' < 'w')
return (char, random) ? true : false;
}
while (runAgain) {
for (let i = 0; i < 5; i++) {
let random = arr[Math.floor(Math.random() * arr.length)]
let char = prompt('Enter s, w, g')
alert('You entered ' + char)
if (char == random) {
alert('Tie')
}
else {
if (char > random) {
alert('Computer generated ' + random + ' So, You are winner')
}
else {
alert('Computer generated ' + random + ' So,Computer is winner')
}
}
if (char > random) {
score++;
}
else {
score = score + 0;
}
alert('Your score is ' + score + ' out of 5.')
}
runAgain = confirm('Do you want to play Again?')
}