logo Practice-It logo

rockPaperScissors

Language/Type: JavaScript if/else console output
Author: Melissa Medsker-Galloway (on 2016/11/18)

Write a function called rockPaperScissors that takes two parameters: a string representing a first player's move in a game of Rock-Paper-Scissors and a string representing a second player's move. Depending on each player's move, the function should output to the console the winner of the round if there was a winner, a tie if both players had the same move, or whether a player gave an invalid move. When comparing moves, letter-casing does not matter ("rock" should be considered the same move as "rOcK").

The two-player game of Rock-Paper-Scissors works as following:

  • Each player chooses one of three moves: "rock", "paper", or "scissors"
  • A move of "rock" wins over another player's move of "scissors"
  • A move of "scissors" wins over another player's move of "paper"
  • A move of "paper" wins over another player's move of "rock"
  • If two players use the same move, the result is a tie

For example, a call of rockPaperScissors("rock", "scissors") would result in console output of "Player 1 wins!". A call of rockPaperScissors("ROCK", "Paper") would result in console output of "Player 2 wins!". A call of rockPaperScissors("SCISSORS", "Scissors") would result in console output of "TIE!". If one player gives a move other than "rock", "paper", or "scissors", the console output should be "Invalid move of [player's invalid move]!", where you should replace [player's invalid move] with the exact value passed by that player. If both players pass invalid moves, the console output should be "Invalid moves of [player 1's invalid move] and [player 2's invalid move]!".

Type your solution here:


This is a function problem. Write a JavaScript function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.