Important Notice:

Practice-It will be discontinued as of November 1st, 2024. After this date, the website will remain online for a transitional period, but login will be restricted to University of Washington NetID authentication. This marks the next phase towards the platform's full retirement. Thank you for your use and support of the application over the years.

If you are looking for an alternative, a similar tool, CodeStepByStep, was developed independently by the original author of Practice-It, and is available at codestepbystep.com**

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.