How can I call this function?


#1


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


Says that " Instead of saying undefined, your code returned 'The results are a tie!' when the inputs are Rock and Scissors'"


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


#2

i don't understand this lines:

var choice1 = userChoice;
var choice2 = computerChoice;

you can pass the choices when calling the function, it is rare to overwrite the function parameters like you did

remove this lines, and try adding a function call


#3

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