My javascript code keeps saying undefined

Hi guys I been working on codeacamedy to learn javascript and I have complated the rock,paper,scissor game but I keep getting undefined. Could you please tell me what is wrong with my code.

function getUserInput (userInput) {
  userInput = userInput.toLowerCase();
  return userInput;
}

function getComputerInput (computerInput) {
  computerInput = Math.floor(Math.random()*3)
  switch (computerInput) {
    case 0:
      computerInput = "rock";
      break;
    case 1:
      computerInput = "scissors";
      break;
    case 2:
      computerInput = "paper";
      break;
  }
  return computerInput;
}

function comparasion (userInput, computerInput) {
  if (userInput === computerInput) {
    console.log ("It is a tie");
  } else if ( userInput === "rock" || computerInput ==="paper" || userInput === "paper" || computerInput ==="scissors" && userInput === "scissors" || computerInput ==="rock") {
    console.log("Computer wins");
  } else if ( userInput === "paper" || computerInput ==="rock" || userInput === "paper" || computerInput ==="scissors" || userInput === "scissors" || computerInput ==="paper" ) {
    console.log ("User wins");
}
}

function playGame () {
  const userInput = getUserInput("paper");
  const computerInput = getComputerInput ();
  console.log (`Your choice is ${userInput} and the computer choice is ${computerInput}. The result is`);
  console.log (comparasion (userInput, computerInput));
}

playGame ();

your comparasion function does not return anything, why not? I would return computer/user wins.

How would I do that? And why should I do that could you please be more specific.

the return keyword has been taught, right? Handing a value back to the function call.

i think returning the outcome for the comparison makes more sense design wise. Can you link the project? I think the exercise/project also recommends return

Well yes they thought me return but in this case I still dont understand the problem so that is why I asked I am sorry for the trouble.

Rock,Paper,Scissorts

undefined indicate the absence of a return value, here:

function comparasion (userInput, computerInput) {
  if (userInput === computerInput) {
    console.log ("It is a tie");
  } else if ( userInput === "rock" || computerInput ==="paper" || userInput === "paper" || computerInput ==="scissors" && userInput === "scissors" || computerInput ==="rock") {
    console.log("Computer wins");
  } else if ( userInput === "paper" || computerInput ==="rock" || userInput === "paper" || computerInput ==="scissors" || userInput === "scissors" || computerInput ==="paper" ) {
    console.log ("User wins");
}
}

yet when you call the function:

console.log (comparasion (userInput, computerInput));

you log the return result. But there isn’t a returned result, so you get undefined (the absence of a return value)

function comparasion (userInput, computerInput) {
  if (userInput === computerInput) {
    console.log ("It is a tie");
  } else if ( userInput === "rock" || computerInput ==="paper" || userInput === "paper" || computerInput ==="scissors" && userInput === "scissors" || computerInput ==="rock") {
    console.log("Computer wins");
  } else if ( userInput === "paper" || computerInput ==="rock" || userInput === "paper" || computerInput ==="scissors" || userInput === "scissors" || computerInput ==="paper" ) {
    console.log ("User wins");
}
}

This whole logic is flawed, and will not determine a winner. The instructions ask you to use separate if statements each with a nested if/if else/else. For example:

  if (userChoice === computerChoice) {
    return 'It\'s a tie!';
  }
  if (userChoice === 'rock') {
    if (computerChoice === 'paper') {
      return 'Computer wins!';
    } else {
      return 'User wins!';
    }
  }

If you really wanted to compress all the conditions into a single if statement, you can, but it would need to look more like this: (Don’t look until you try fixing it yourself :wink:)

  if ((userChoice === 'rock' && computerChoice === 'paper') || (userChoice  === 'paper' && computerChoice === 'scissors') || (userChoice === 'scissors' && computerChoice === 'rock')) {
    return 'Computer wins!';
  } else {
    return 'User wins!';
  }

Okey I understand thank you so much for your help I tried everything but now i got an answer