Part 8- Return paper wins rather than undefined


#1

Wrote my program and now i keep get the error "Oops, try again.
Your code returned 'paper wins' instead of 'undefined' when the inputs are scissors and rock"

:frowning:
pls help

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(choice1, choice2){
    if (choice1 === choice2){
        return ("The result is a tie!");
    }
    else if (choice1 === "rock")
    {
        if (choice2=== "scissors")
        {
            return ("rock wins");
        }
        else
        {
            return ("scissors wins");
        }
    }
    else if (choice1=== "paper")
    {
        if(choice2=== "rock")
        {
            return ("paper wins.");
        }
        else 
        {
            return ("scissors wins");
        }
    }
    else if (choice1 === "scissors")
    {
        if(choice2=== "paper")
        {
            return ("scissors wins");
        }
        else 
        {
            return ("paper wins");
        }
    }
}

compare(userChoice, computerChoice);


#2

This is not expected until the next lesson. It is not yet asked for.

    else if (choice1 === "scissors")
    {
        if(choice2=== "paper")
        {
            return ("scissors wins");
        }
        else 
        {
            return ("paper wins");
        }
    }

#3

take a look at this code:

else if (choice1 === "scissors")
    {
        if(choice2=== "paper")
        {
            return ("scissors wins");
        }
        else 
        {
            return ("paper wins");
        }
    }

your else returns paper wins, but if else runs, that mean choice2 is rocks, so rock should win (aka, rock wins should be returned)

@mtf, part8 is what if choice1 is scissors, so i think is perfectly reasonable to have this code


#4

hahahahaha fml thank you


#5

The final else if is not asked for until the last lesson. Will have to track down this lesson and check, to be sure. This error comes up a lot. Man, I wish people would post the link to the exact exercise. We don't have this stuff on speed dial.


#6

from exercise 8:

which indicate else is required, but then the correct thing should be returned. Which is not the case in arcslayers code


#7

Yes, I'm reading that now. It must be a quirk in the SCT. I removed that last else if and the call to compare, and the lesson passed.

Ran the complete code, entered scissors and passed the lesson. I must be thinking of lesson 7 not expecting the last else if. This lesson should not have given that SCT error message. Did the OP mean Lesson 7?


#8

This is correct. Didn't even look at that...