6. What if choice one is rock


#1

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";
}
};

What am I doing wrong?


#2

Hi you missing the closing } of the compare function

var compare = function(choice1, choice2) {
if ( condition) {

}
else if {
    if ( condition) {

    }
    else {


}

}
} <== this one

#3

It didn't work :confused:


#4

Hi can you post your new code?


#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 if(computerChoice <= 0.67) {

/Thanks for helping


#6

here you close the compare function earlier so remove one }

if (choice1 === choice2) {
    return "The result is a tie!";
}<= remove this one 
};

#7

didnt work, whats the correct one supposed to look like? I must have a couple issues :smile: . Thank you for helping me by the way.


#8

and try to remove all the ; after the }


#9

Alright I'll try to do that.


#10

Didn't work :confused:


#11

you code is like that

/*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";
    }
}
}

if it's tell me on what lesson are you ?


#12

6 What if choice1 is rock?


#13

so your code should be that

/*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";
    }
}
}

#14

Thank you :smiley: that worked