I am not getting the return value in console


#1


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

My code seems working fine but am not getting the results on the console like Rocks Wins , Paper wins etc.. All I am getting is computer : paper ... Heres 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(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";
        }
        
}
};


#2

Your function should take the parameters choice1 and choice2


#3

Here as well refer to userChoice and computerChoice as choice1 and choice2.


#4

ok but somewhere they asked us to replace the choice1 and choice2 to userchoice and computechoice..any way lemme try as you have asked... but why does that make difference


#5

Tried but not working..

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 "paper wins";
    }

}
};


#6

userChoice and computerChoice are defined variables, which is why assigning them as parameters for your compare function overwrites their initial instructions.


#7

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