8. What if choice1 is scissors?


#1

At this stage we are told in the instructions to call the functions userChoice and computerChoice, but we are not told what to call them. I have tried a few possibilities but they haven't worked.

userChoice("what am I called?")


#2

no, you are told to call the compare() function which you build over the past few exercise, and supply userChoice and computerChoice as arguments


#3

I've tried this too because I saw that others in the forum had done this. So I huess the problem is something else that I can't work out...


#4

can you provide your full code + how you have done this? This is impossible for me to guess, and a mistake is easily made


#5

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 (choice1 === "scissors") {
    if (choice2 === "rock") {
        return "rock wins";}
    else { return "scissors wins";}
}    
};
compare(userChoice,computerChoice)

#6

What confuses me the most is that at this stage I haven't really changed anything, all I have done is to call the functions


#7

you also added what if choice1 is scissors:

else (choice1 === "scissors")

else can't have a condition, use either else if or remove the condition from else

I would choice the first of the two options


#8

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