JavaScript - Functions: Rock, Paper, Scissors - Which is the utility of : else { return 'text'; }

Hi Friends!
(i was trying to fix it in my mind, but I fail)

In this project, following all steps and video(get stuck) I can note that:

**const determineWinner = (userChoice, computerChoice) => {**
**  if (userChoice === computerChoice) {**
**    return 'The game is a tie!';**
**  }**
**  if (userChoice === 'rock') {**
**    if (computerChoice === 'paper') {**
**      return 'The computer won!';**
**    } else {  <------- HERE ----------- AND TO BELLOW **
**      return 'You won!';  <------  HERE, DONT MAKE NOTHING.**
**    }**
**  }**

I thought this would be given THAT OTHER RESULT case if the choices changed between USER and COMPUTER, however, it doesn’t work… Or other way, I literally don’t learn nothing about it… :frowning: ?


The function you wrote is completely fine in terms of it working. The inner if statement only lives inside the outer if statement which is only triggers if userChoice === "rock"…

Now, you might want to consider what happens when a function returns a value (it won’t log to the console for example). Note, that in terms of functionality, a console.log is only useful insomuch as it informs us of the state of a variable… whereas return helps us move, store, and process information in other operations.

For future posts, check out how to format your code as this will make it easier to get help: [How to] Format code in posts

1 Like

Ok , thank you so munch! :wink: