Some help please with "what if choice 1 is paper?"


#1

var compare = function (choise1, choise2){
    if (choise1 === choise2) {
        return "The result is a tie!";
    }
    else if (choise1 === "rock"){
         if (choice2  ==="sciccors") {
            return"rock wins";
    }
   }
    else {
        return "paper wins";
    }
   if (choice1 === "paper");{
         if (choice2 === "rock"){
            return "paperwins";
        }
    
        else {
            return "scissors wins";
        }
}
    
};

What if choice 1 ist paper?
#2

Careful with your spelling, that could play tricks on your code...

choise1, choise2
choise1 === "rock"
choice2 ==="sciccors"
choice1 === "paper"
choice2 === "rock"


#3

here:

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

the else not nested inside the else if, which means you can't use else if here:

if (choice1 === "paper");{

while you should, you even have an unnecessary in this line of code


#4

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