Open CamruthaV opened 5 days ago
You will build a Rock-Paper-Scissors game where the computer randomly selects a move, and the player’s move is compared against it to determine a winner. This project will focus on using JavaScript, Node.js, and backend fundamentals.
Math.random()
to generate the computer’s choice in the game.
function getRandomMove() {
const moves = ["rock", "paper", "scissors"];
return moves[Math.floor(Math.random() * moves.length)];
}
function determineWinner(playerMove, computerMove) {
if (playerMove === computerMove) return "Draw";
if (
(playerMove === "rock" && computerMove === "scissors") ||
(playerMove === "scissors" && computerMove === "paper") ||
(playerMove === "paper" && computerMove === "rock")
) {
return "Player wins!";
} else {
return "Computer wins!";
}
}
const playerMove = "rock"; // This could come from user input
const computerMove = getRandomMove();
console.log(`Player: ${playerMove}, Computer: ${computerMove}`);
console.log(determineWinner(playerMove, computerMove));
What Roadmap is this project for?
Backend
Project Difficulty
Beginner
Add Project Details
Build a rock paper scissor game using random function