I have made "Snake, Water and Gun game" using javascript. It is a simple game project which is similar to the rock paper scissor game so, it is very fun to play. I have made this project in replit.
How does it work?
Firstly, we have to let snake as "S" water as "W" and gun as "G".In this game, there are two players i.e user and CPU. You just have to use the cursor to click on the symbol (snake, water, or gun) as per your wish. Then you choose random symbol and the result is shown after you run the game.
This game consists of a lot of JavaScript validations. This game is fun to play. You can use any browser to run this game. You can use the following source code to play the game.
Source code
let user = prompt("Lets play the game.Enter S, W or G")
let game = Math.floor(Math.random() * 3);
let cpu = ["S", "W", "G"][game]
const match = (cpu, user)=>{
if(cpu === user){
return ("Nobody won ")
}
else if(cpu === "S" && user==="W"){
return ( "cpu won the game")
}
else if(cpu === "S" && user==="G"){
return( "congratulation!You won the game ")
}
else if(cpu === "G" && user==="W"){
return "congratulation!You won the game "
}
else if(cpu === "G" && user==="S"){
return "cpu won the game "
}
else if(cpu === "W" && user==="S"){
return "congratulation!You won the game "
}
else if(cpu === "W" && user==="G"){
return "cpu won the game "
}
}
let result = match(cpu, user)
document.write(`Cpu:${cpu} <br> User:${user} <br> Result:${result}`)
Output
Conclusion:
This is really fun to create and play the game.
Hope you like this "Snake,Water and Gun " game.
In this post, we learned how to create a Snake,Water and Gun using simple javascript.
