Rock, Paper, or Scissors

I am doing the exercise: rock, paper or scissor.

I have a doubt here: why the parenthesis are empty ()?
and in case I want write into it what should i write?

const getComputerChoice = () here => {
const randomNumber = Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return ‘rock’;
case 1:
return ‘paper’;
case 2:
return ‘scissor’;
}
};
console.log(getComputerChoice());

1 Like

The parenthesis are part of an arrow function, just like with the function keyword you can add arguments, and do certain things with the arguments that will be defined when calling the function, you can think of them as if they were variables, unlike variable we don’t know what will be their values (until we call the function and pass arguments into them).

setting their arguments are:

const testFunction = () => {
  /* no arguments */
}

const testFunction = argument1 => {
  /* one argument */
}

const testFunction = (argument1, argument2) => {
  /* multiple arguments */
}

In this case you shouldn’t need any arguments because this function doesn’t require one.
But for example an addition function would need two arguments:

const add = (first, second) => {
  return first + second;
}
console.log(add(1, 2)); // logs 3 to the console

There are functions with arguments used in the project you’re doing, for example the getUserChoice function

Hope this helps :grinning:

1 Like

Yes absolutely @lolfail. Thank you!!!:slightly_smiling_face:
Just I don’t understand why in this case we don’t need to add any argument.
It’s because in automatic the function will take the value from the block?

1 Like

@andreawlee you don’t need to add an argument because the function does not require one.

Upon calling it generates a random number and provides output accordingly.

See it as the difference between,

I ask you to tell a story. You tell me a story based on your own imagination.

vs

I ask you a story and say you have to use the word Duck, car and tin opener. You now have to come up with a story which includes those words.

2 Likes

Thank you @janneslohmeijer :upside_down_face:

2 Likes