Help with rock, paper, scissors project

//checks if input equals to rock, paper or scissors, if not gives error
const getUserChoice = (userInput) => {userInput = userInput.toLowerCase(); if (userInput === “rock” ||userInput === “paper” || userInput === “scissors”){return userInput;}else {console.log(“Error!”);}};

//prints a random value of either rock paper or scissors
function getComputerChoice(){
const randomNumber = Math.floor(Math.random()*3);
switch (randomNumber)
case 0:
return “rock”;
case 1:
return “paper”;
case 2:
return “scissors”;

//checks to see if user won the match between computer and human input
function determineWinner(userChoice, computerChoice){
if(userChoice === computerChoice){
return console.log(“game was a tie”);
} else if (userChoice === “rock” && computerChoice === “paper” ||userChoice === “paper” && computerChoice === “scissors” || userChoice === “scissors” && computerChoice === “rock”)
return console.log(“You Lost!”);
}else {console.log(“You Won!”);}
//acts as constructor for setting the values for determineWinner
function playGame(){
const userChoice = getUserChoice(“paper”);
const computerChoice = getComputerChoice();
console.log(the choice was ${userChoice} and the ai chose ${computerChoice});
console.log(determineWinner(userChoice, computerChoice));

This is what i did but every time I run it it gives me a what i want to be printed, along with undefined. I don’t know where I went wrong.

You have mixed in some console.log()'s with return's and it’s causing the undefined to appear. Have a look at the determineWinner() function again and see if you can spot where you’ve gone wrong with this. Remember a function will return undefined if a return value is not explicitly stated.


Thank you so much! I got it :slight_smile: :smiley:

1 Like

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