Lesson 6 I don't know what I'm doing wrong


#1

} else if(computerChoice <= 0.67) {
/*var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
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==="paper") {

if(choice2 === "rock")
return"paper wins";
}
else {
This seems to be what it says to do, but is says "SyntaxError: Unexpected token else"


Lesson 6 "What if Choice1 Is Rock?"
#2

Hi you should close your else statement like that

else  {
     return "paper wins"
}
}  <== you should close your compare function here

And remove one } after the first if statement


#3

thanks ill try that and let you know if it works


#4

so i did that and it says "SyntaxError: Unexpected token }"


#5

you also forgot to open the if statement "{" so it should be like that

var compare = function (choice1, choice2) {
if(choice1===choice2) {
return "The result is a tie!"
}

else if(choice1==="paper") {
    if(choice2 === "rock") { < === this one 
        return"paper wins";
}
else {
    return "paper wins"
}
} 
}

#6

it still says "SyntaxError: Unexpected token }"


#7

this is what i have

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

}
}
}


#8

but it says "SyntaxError: Unexpected token }"


#9

Hi I m sorry but the first code that you post got this on top } else if(computerChoice <= 0.67) { can you try to post all your new code.


#10

sure
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);*/

var compare = function (choice1, choice2)
if(choice1===choice2) {
return "The result is a tie!"
}
};

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

}
};
}


#11

hey for some reason i had in my else statment "paper wins"; so i changed that to scissors like the instructions said. so my new code is this

} else if(computerChoice <= 0.67) {
/*var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
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==="paper") {
if(choice2 === "rock") {
return"paper wins";
}
else {
return "scissors wins";

}
};
}

though that wasnt the problem


#12

Hi this part

} else if(computerChoice <= 0.67) { < === that shouldn't be here
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) {  <=== should be here 
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);

And also

var compare = function (choice1, choice2) 
if(choice1===choice2) {
return "The result is a tie!"
}
};<=== that shouldn't be here because its close the compare function 

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

}
};
} <=== the compare function should be close here

#13

oh ok ill try that and tell you what happens


#14

so i did that this is 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==="paper") {
if(choice2 === "rock") {
return"paper wins";
}
else {
return "paper wins"

}
};
}

but now it says "SyntaxError: Unexpected token if"


#15

var compare = function (choice1, choice2) { < =  add one
if(choice1===choice2) {
return "The result is a tie!"
}
}; <=== remove that one

#16

ok, it still says "SyntaxError: Unexpected token if"


#17

The error is that else if and else statement return the same thing so change it .
THE first one should return return rock wins
And the second one is right

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

}
};
}

And all you code should be like

var compare = function (choice1, choice2) 
if(choice1===choice2) {
return "The result is a tie!"
};

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

}
};
}

#18

i did that and it says "SyntaxError: Unexpected token if'


#19

Hi post your new code like that

 ```
Code
 ```

#20

ok

/*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==="paper") {
    if(choice2 === "rock") {
        return"rock wins";
}
else {
    return "paper wins"

}
};
}