-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathsnakeWaterGunGame.js
More file actions
67 lines (62 loc) · 1.49 KB
/
snakeWaterGunGame.js
File metadata and controls
67 lines (62 loc) · 1.49 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
const prompt=require("prompt-sync")({sigint:true});
const character ='SWG';
function SWG(){
return character[Math.floor(Math.random()*3)];
}
let rounds=parseInt(prompt("Enter no of rounds you want to play : "))
console.log("===SNAKE WATER GUN===");
console.log("Enter S for Snake | W for Water | G for Gun");
let userPoints=0 , computerPoints=0;
while(rounds)
{
user=prompt("Enter your choice : ");
computer=SWG();
console.log("computer ->"+computer);
if(user=="S"||user=="s" && computer=="W" )
{
console.log("You win this round");
userPoints++;
}
else if(user=="G"||user=="g" && computer=="W")
{
console.log("You loss this round");
computerPoints++;
}
else if(user=="W"||user=="w" && computer=="S")
{
console.log("You loss this round");
computerPoints++;
}
else if(user=="W"||user=="w" && computer=="G")
{
console.log("You win this round");
userPoints++;
}
else if(user=="S"||user=="s" && computer=="G")
{
console.log("You loss this round");
computerPoints++;
}
else if(user=="G"||user=="g" && computer=="S")
{
console.log("You win this round");
userPoints++;
}
else
{
console.log("Round tie");
}
rounds--;
}
if(userPoints>computerPoints)
{
console.log("\nYOU WIN 🎉🎉")
}
else if(computerPoints>userPoints)
{
console.log("\nYOU LOSS 😭")
}
else
{
console.log("\nGAME TIE 😑")
}