Files
freecodecamp--freecodecamp/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/6925e2068081f40f549ced1d.md
T
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.9 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6925e2068081f40f549ced1d Challenge 139: Rock, Paper, Scissors 28 challenge-139

--description--

Given two strings, the first representing Player 1 and the second representing Player 2, determine the winner of a match of Rock, Paper, Scissors.

  • The input strings will always be "Rock", "Paper", or "Scissors".
  • "Rock" beats "Scissors".
  • "Paper" beats "Rock".
  • "Scissors" beats "Paper".

Return:

  • "Player 1 wins" if Player 1 wins.
  • "Player 2 wins" if Player 2 wins.
  • "Tie" if both players choose the same option.

--hints--

rockPaperScissors("Rock", "Rock") should return "Tie".

assert.equal(rockPaperScissors("Rock", "Rock"), "Tie");

rockPaperScissors("Rock", "Paper") should return "Player 2 wins".

assert.equal(rockPaperScissors("Rock", "Paper"), "Player 2 wins");

rockPaperScissors("Scissors", "Paper") should return "Player 1 wins".

assert.equal(rockPaperScissors("Scissors", "Paper"), "Player 1 wins");

rockPaperScissors("Rock", "Scissors") should return "Player 1 wins".

assert.equal(rockPaperScissors("Rock", "Scissors"), "Player 1 wins");

rockPaperScissors("Scissors", "Scissors") should return "Tie".

assert.equal(rockPaperScissors("Scissors", "Scissors"), "Tie");

rockPaperScissors("Scissors", "Rock") should return "Player 2 wins".

assert.equal(rockPaperScissors("Scissors", "Rock"), "Player 2 wins");

--seed--

--seed-contents--

function rockPaperScissors(player1, player2) {

  return player1;
}

--solutions--

function rockPaperScissors(player1, player2) {
  if (player1 === player2) return "Tie";

  if (
    (player1 === "Rock" && player2 === "Scissors") ||
    (player1 === "Paper" && player2 === "Rock") ||
    (player1 === "Scissors" && player2 === "Paper")
  ) {
    return "Player 1 wins";
  } else {
    return "Player 2 wins";
  }
}