Learn javascript: functions


Please help, determineWinner function does not work.

const getUserChoice = userInput => {
if (userInput === “rock” || userInput === “paper” || userInput === “scissors”) {
return userInput;
} else {
console.log(“Error message”);

const getComputerChoice=()=> {
randomNumber= Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return “rock”;
case 1:
return “paper”;
case 2:
return “scissors”

const determineWinner=function(getUserChoice, getComputerChoice){
if (getUserChoice === getComputerChoice){
return “Tie game”;


Is this an exercise? Or a practice session?

Parameters to a function should not be function names. It will take some testing to be sure but I don’t believe function names are shadowed by local names. Use plain, local variables for the parameters.

 function(userChoice, computerChoice)

The call to the function may contain calls to the other two…

console.log(determineWinner(getUserChoice(), getComputerChoice());


Thank you for your answer.

It is a project. Rock, Paper, Scissors

I have to compare 2 functions. Last function does not work.


I found a problem.
It works. Yes, yes, yes…

const determineWinner= (getUserChoice, getComputerChoice)=>{
if (getUserChoice === getComputerChoice){
return “Tie game”;


The userChoice function is to take a parameter, userInput, so,

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


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.