Please help, determineWinner function does not work.
const getUserChoice = userInput => {
if (userInput === “rock” || userInput === “paper” || userInput === “scissors”) {
return userInput;
} else {
console.log(“Error message”);
}
};
console.log(getUserChoice(“rock”));
const getComputerChoice=()=> {
randomNumber= Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return “rock”;
case 1:
return “paper”;
case 2:
return “scissors”
}
}
console.log(getComputerChoice());
const determineWinner=function(getUserChoice, getComputerChoice){
if (getUserChoice === getComputerChoice){
return “Tie game”;
}
};
mtf
April 13, 2018, 6:38pm
#2
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.
1 Like
I found a problem.
It works. Yes, yes, yes…
const determineWinner= (getUserChoice, getComputerChoice)=>{
if (getUserChoice === getComputerChoice){
return “Tie game”;
}
}
console.log(determineWinner());
mtf
April 14, 2018, 5:48pm
#5
The userChoice
function is to take a parameter, userInput
, so,
console.log(determineWinner(getUserChoice('rock'), getComputerChoice());
system
closed
April 21, 2018, 5:48pm
#6
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.