I am so confused, what are they asking me to do in this part?


#1


Guys, I am so stuck. I just completely have no idea what they're asking me to do? If you look at the last line of my code, that's my wild guess as to what I'm supposed to do here. Can someone please explain to me what they're asking in layman's terms? Sometimes the instructions just absolutely don't make sense. Thanks!


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

Here's the error I'm getting.

Computer: rock
TypeError: userChoice is not a function. (In 'userChoice("scissors")', 'userChoice' is "scissors")

Here's 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";
}

else if(choice1 === "rock") {

    if(choice2 === "scissors") {
        return "rock wins";
    }
    else {
        return "paper wins";
    }

}
else if(choice1 === "paper") {

    if(choice2 === "rock") {
        return "paper wins";
    }
    else {
        return "scissors wins";
    }

}
else if(choice1 === "scissors") {

    if(choice2 === "paper") {
        return "scissors wins";
    }
    else {
        return "rock wins";
    }

}
};

userChoice("scissors");


#2

You're panicking, take a deep breath!

They're Just asking what if your answer to userChoice promp is scissors. userChoice is not a function, userChoice is equal to your prompt, don't redeclare it. You're declaring the wrong function.

// userChoice is equal to whatever you enter in
// the prompt (prompt is the pop up window asking for your input)
// The prompt will pop up on it's own now that you've assigned it, no need to call this variable again.
var userChoice = prompt("Do you choose rock, paper or scissors?");

// Math.random() returns a random floating point number between 0 & 1.
var computerChoice = Math.random();

// Because we only have three options, we divide 1 by 3 and check these
// three floating point constraints, if random returns a float within these
// checks, the computer's answer is that check.
if (computerChoice < 0.34) {
	computerChoice = "rock"; // Assign the new string to computerChoice
} else if(computerChoice <= 0.67) {
	computerChoice = "paper"; // Assign the new string to computerChoice
} else {
	computerChoice = "scissors"; // Assign the new string to computerChoice
}

// Debugging: allows us to see that computerChoice was given a string
console.log("Computer: " + computerChoice);


// Now that we have usrChoice & computerChoice, we need to determine who wins?
// Introduce our compare function (yes this IS a function)

// This function takes two parameters, our userChoice & computerChoice. Below we are 
// building the function, but at some point we want to actually call it, passing our answers into it.
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";
    }

}
else if(choice1 === "paper") {

    if(choice2 === "rock") {
        return "paper wins";
    }
    else {
        return "scissors wins";
    }

}
else if(choice1 === "scissors") {

    if(choice2 === "paper") {
        return "scissors wins";
    }
    else {
        return "rock wins";
    }

}
};


// This is where you panicked and put down the wrong answer. I hope the explanation helped, and that you know the answer.

#3

Thank you SO MUCH for breaking that down for me. With your help, I tried a couple other things, which led me to the right answer!!!!


#4

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