Make sure to call your compare function with userChoice and computerChoice as the arguments!


#1


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


Oops...try again! Make sure to call your compare function with userChoice and computerChoice as the 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 (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";
                }
        }   
        
        else if (userChoice === "scissors") {
        if (computerChoice === "paper") {
            return "scissors wins";
        }
        else {
            return "rock wins";
        }
    }
    }


#2

Did you notice you wrote your else if statement twice?

As far as calling your function goes, all you need to do is write the name of your function on the next line of code along with its arguments (userChoice,(computerChoice).


#3

THANK YOU!!!!! That helped!


#4

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