Function Problem


Good night everyone. I'm a begginer, as u guys will see. can somebody help me?

Oops, try again. Your code returned 'paper wins.' instead of 'undefined' when the inputs are scissors and rock

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
	computerChoice = "rock";
} else if(computerChoice <= 0.67) {
	computerChoice = "paper";
} else {
	computerChoice = "scissors";
} console.log("Computer: " + computerChoice);

var compare = function(userChoice,computerChoice){
    if(userChoice === computerChoice){
        return "The result is a tie!";
   else  if (userChoice === "rock"){
    if (computerChoice ==="scissors"){
        return "rock wins";
        else {
        return "paper wins";
        else if (userChoice==="paper"){
                return " paper wins"}
                    return"scissors wins"}
            if(computerChoice === "paper"){
                return "scissors wins"}
                    return "paper wins."}



The SCT is not expecting the final else if block to exist yet. The function should return undefined. Comment out or remove that segment of code, and add it back in the next lesson.


thank u. But there's still a problem. I'm sorry to bother again.In the next step, however is my choice among rock, paper or scissor the result is always a tie. the compare function it's not working. but thank u so far for ur help.


Are you getting any error messages, or just not seeing any output?

console.log(compare( ..., ... ));

to see the output.


i'm not seeing any error message but i'm seeing the output.
the output is always" the result is a tie" though.
Like that:
Computer: scissors
"The result is a tie!"


else if (userChoice = "scissors") {
    if ( ... ) {


A post was split to a new topic: call your compare function with userChoice and computerChoice as the arguments