Is codeacademy broken?


#1

I've been working for about an hour on this, and so far the program runs the way it should be.
I get prompted asking me to input a value of, "rock, paper, or scissors", and then after the computer randomly chooses a value as well and then compares the two.
Only problem is, it keep giving me an error message saying it should return, "undefined".

Here is my code.

    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!");
        }
        
        if (choice1 === "rock") {            
            if (choice2 === "scissors") {
                return ("rock wins");
            }            
            else {
                return ("Paper wins");
            }            
        }
        
        if (choice1 === "paper") {            
            if (choice2 === "rock") {
                return ("paper wins");
            }            
            else {
                return ("scissors wins"); 
            }
        }
        
        if (choice1 === "scissors") {            
            if (choice2 === "paper") {
                return ("scissors wins");
            }            
            else {
                return ("paper wins"); 
            }            
        }
        
}

compare(userChoice, computerChoice);

#2

Your code is fine only thing i can see is to see the result of the comparison you need to pass the call of that method to console.log

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

#3

Tried that but still gives the same output.
It's weird on the small console it says;

computer: paper
"scissors wins!"

But below that the error message says my code returns, "Paper wins" instead of, "undefined"


#4

try this for your compare function. take a look at the diferences between yours and this and you will see the changes

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

#5

Thank you, that seemed to work.
Although to be completely honest i couldn't find any differences in the code.

Is there a specific area that i should look at?