Js-Don t understand something in the rock/P/Scissors game

Hi everyone, //The code follows the question.

I’m doing the JS exercise on the Rock Paper Scissors game. And I don’t understand how the web browser knows that the “userChoice” and “computerChoice” parameters represent the user’s and computer’s choice.

I understand how to build the “getUserChoice” and “getComputerChoice” functions. However, it seems more logical to me to have some kind of link between “userChoice” (and “computerChoice”) and the result of the getUserChoice" (and “getComputerChoice”) functions before treating them later with the “if statement”.
For example a link like this one;

var getComputerChoice = “userChoice”;

It seems to me that writing “userChoice” (where indicated in the code by the sign <<<<<<<<<<<<<<<<HERE IS MY ISSUE) implies that “userChoice” is a new variable and not defined in addition, so I don’t understand how the computer makes the link

const getUserChoice = userInput => {
if (userInput === ‘rock’ || userInput === ‘scissors’ || userInput ===‘paper’) {
return userInput;
} else {

const getComputerChoice = () =>{
const randomNumber = Math.floor(Math.random() * 3);
switch(randomNumber) {
case 0:
return ‘rock’;
case 1:
return ‘paper’;
case 2:
return ‘scissors’;
let = determineWinner = (userChoice, computerChoice) =>{ /<<<<HERE IS MY ISSUE)
if(userChoice === computerChoice) { /<<<<HERE IS MY ISSUE)
return “The game is tie!”;
if (userChoice === “rock”) {
if (computerChoice === ‘paper’){
return’Computer won’;

1 Like

That should be const instead of let because it is a function.

The browser doesn’t know, they will be defined when calling the function:

console.log(determineWinner(getUserChoice('rock'), getComputerChoice()))

In this example we use the determineWinner function,
the userChoice parameter is defined by the getUserChoice and we set it’s attribute to our chosen element, the other attribute of determineWinner is the randomiser function.
Then we log it to the console, because the determine function will only return a value.
If this was your question I hope this helps :grinning:

1 Like

I understood thank you so much.
XD >>>>> console.log(determineWinner(getUserChoice(‘rock’), getComputerChoice()))

It make sense.