Rock, Paper or Scissors Project.... playGame() function parameter?

Exercise link: https://www.codecademy.com/paths/back-end-engineer-career-path/tracks/fscp-javascript-syntax-part-i/modules/fecp-learn-javascript-syntax-functions/projects/rock-paper-scissors-javascript

Why aren’t we adding a parameter to the playGame() function so that we can invoke it as an argument like so?

const playGame = (choice) => {
let userChoice = getUserChoice(choice);
let computerChoice = getComputerChoice();
console.log(You threw: ${userChoice}!);
console.log(The computer threw: ${computerChoice}!);

// Prints to see who won
console.log(determineWinner(userChoice, computerChoice));
}

// Start the Game
playGame(‘scissors’);

I feel like it makes more sense to call the playGame() function this way ?

It makes sense, but you don’t have to. I you were getting input from the user, you’d probably have it within the function (since the function is meant to, well, play the game). I think the idea with these projects is that you can do it your way; so if you want a parameter, there’s no reason not to.

1 Like