7. what if choice1 is paper? need help


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

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

#2

You close your else if directly instead of wrapping the nested if else.


#3

how may i fix it ? i cant seem to fix it @haxor789


#4

Hi all your else if statement should have this structure
in the first case

else if (choice1 === "rock"){
        if (choice2 === "scissors"){
            return "rock wins"    
        }
        
        else {
            return "paper wins"    
        }
    } <== this is where you have to close the else if

#5

hi i went back to do it like this but its not working @wizmarco

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

#6

Hi try to post all the new code


#7

heres my new code @wizmarco
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"; 
    } 
}

#8

Hi first in this line console.log("Computer: " + computerChoice);*/ you should remove */ and then its mising the "}" closing of your var compare so at the end add a "}"