What if choice1 is scissors?


#1


https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/4?curriculum_id=506324b3a7dffd00020bf661#


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

this is my error message and I know for a fact that my code runs

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") {
        if (computerChoice === "rock") {
            return "paper wins";
            }
            else {
                return "scissors wins";
                }
        }
    else if (userChoice === "scissors") {
        if (computerChoice === "paper") {
            return "scissors wins";
            }
            else {
                return "paper wins";
                }
        }
    else {}    
    };
    console.log(compare(userChoice, computerChoice));

I figured it out..... the last line where return "paper wins" is located needs to be "rock wins"


#2

The final else if segment is written in the next lesson, so just comment it out to continue.


#3

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