Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rock Paper Scissor #7734

Open
CamruthaV opened this issue Nov 14, 2024 · 2 comments
Open

Rock Paper Scissor #7734

CamruthaV opened this issue Nov 14, 2024 · 2 comments

Comments

@CamruthaV
Copy link

What Roadmap is this project for?

Backend

Project Difficulty

Beginner

Add Project Details

Build a rock paper scissor game using random function

@JawherKl
Copy link
Contributor

JawherKl commented Nov 14, 2024

Suggested roadmap

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.

Project Objectives

  • Learn Random Functions: Use JavaScript's Math.random() to generate the computer’s choice in the game.
  • Implement Basic Logic: Develop functions to handle the rules of Rock-Paper-Scissors and determine the winner.
  • Enhance User Interaction: Allow users to input their move, interact with the game, and view the results.

Suggested Steps

  1. Setup: Initialize a Node.js project with basic setup and install necessary packages.
  2. Game Logic: Implement functions to generate random moves, receive user input, and compare the choices based on Rock-Paper-Scissors rules.
  3. Run and Test: Test the game locally to ensure the game logic works as expected.
  4. Extend (Optional): Add extra features like score tracking, or implement the game as a simple API for practice in backend requests.

Sample Code Outline

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));

@ds301056
Copy link

this would have be great for someone just starting their journey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants