5. Both choices are the same


#1


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


I'm done with this, the program keeps insisting that there is something wrong. After 10 minutes looking at the code I decided to copy and paste the code from the hint. But still gives me error.
"
Your compare function does not return 'The result is a tie!' when there is a tie."

I decided to skip it, but other sessions also tell me that I didn't called the function under the "userChoice" and "computerChoice arguments".


/*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";
    }
};

//FINAL CODE, STILL SAYS THAT THERE IS AN ERROR//

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 === "rock"){
            return "rock wins"
        }
        else{
            return "scissors wins"
        }
    }
};


#2

you have to call the function after closing the function.you already closed the function.so just add it
like

console.log(compare(userChoice,computerChoice))

check it,how to call a function
https://discuss.codecademy.com/t/i-do-not-understand-how-to-call-a-function-what-am-i-doing-wrong/37701/7?u=rcodeman


#3

Solved thank you very much. Also the most unexpected error happened because I didn't had the "!" at the end of the string. Really you guys shouldn't make strings case sensitive, just give example strings.


#4

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