Rock, Paper, Scissors Project. How to write If else statement instead of Switch

Hello, I was wondering how to write an If/else statement correctly in task number 5 that would work. In the solution video the teacher wore a switch function but there is an option to write an else statement as well. I wrote the if / else statement my self but did not work.

Here is the link to the exercise:

Below is my code. The first function works, the getUserChoice. The getComputerChoice did not work I get error and undefined result.

const getUserChoice = userInput => {

userInput = userInput.toLowerCase();

if(userInput === 'rock' || userInput === 'paper'

|| userInput === 'scissors') {

  return userInput;

} else {




const getComputerChoice = () => {

  const randomNumber = Math.floor(Math.random() * 3);

  if(getComputerChoice === 'rock' || getComputerChoice === 'paper'

|| getComputerChoice === 'scissors') {

  return getComputerChoice;

} else {





Thank you for your help.

a string ('rock', 'paper' or 'scissocrs') will never equal a function (getComputerChoice).

after you generate the random number, we can use this random number as index on a list of possible options. This way, we have a random choice.

Hello stetim94, thanks for your reply. I’m not quite sure I understand what you mentioned in your reply that a string will never equal to the function (getComputerChoice).

How would someone write an if else statement for the getComputerChoice ? task number 5 gives the option to write either a if else statement or a switch statement. I want to know how someone will write an if else statement for this function. I watch the get help video and the teacher decided to use a switch statement but again the task says either switch or a if else function.

Thanks for your help

that is the crucial part. My point is, what is the value of getComputerChoice?

we can use a simple log to find out:

if(getComputerChoice === 'rock' || getComputerChoice === 'paper'

|| getComputerChoice === 'scissors')

see? getComputerChoice is a function. How will a function ever equal a string?

I then briefly described the process of how it should work:

I on purpose left a lot open here. Generating a random number is only the first step in getting a random choice for the computer.

You miss this step, after you get the random choice, you can validate if the choice is valid.