Computer Choice : Part 2



<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>
SyntaxError: Unexpected token <=


var userChoice = prompt(“Do you choose rock, paper or scissors?”);

var computerChoice = Math.random();


if (computerChoice = 0 && <= 0.33); {
computerChoice = “rock”;

} else if (conputerChoice = 0.34 && <= 0.66) {
computerChoice = “paper”;

} else (computerChoice = 0.67 && <= 1) {
computerChoice = “scissors”;


<do not remove the three backticks above>


it has to do with your condition inside the “if” situation. you don’t use <=. you just use <. that’s what the unexpected token is:

if(computerChoice < 0.33)

the <= means that if its less than or equal too. You just want it to be less than, not both or equal too.


still not working.

var userChoice = prompt("Do you choose rock, paper or scissors?");

var computerChoice = Math.random();


if (computerChoice <= 0.33); {
    computerChoice = "rock";
} else if (conputerChoice >= 0.34) {
    computerChoice = "paper";
} else (computerChoice >= 0.66) {
    computerChoice = "scissors";


fault in typing! Look at your else if >> coMputerChoice instead of coNputerChoice :wink:

and you use =0.34 instead of >=0.34 right?


Not only is there a typo as @barbaraaax has said, but there’s also a semicolon (;) where there shouldn’t be one: [quote=“noobyprogrammer, post:3, topic:33585”]

if (computerChoice <= 0.33); {



your are using the and statement, for and statement both of conditions must be true.
for example if Math.random gives 0.25 the first part of condition will be false and the second one will be true and that returns false.
plus else does not have condition.
my advise is don’t use equal plus fix the semicolons.
fyi: if you’re using equal in Comparison you should use == or ===.
visit if you want to know more.
and sorry for the horrible grammar.


so i did this and it worked but now I’m wondering why. wouldn’t the else if statement cause the rock statement to be true as well since if the number is < .66 it could go below 0.33 and go to rock?

var userChoice = prompt("Do you choose rock, paper or scissors?");

var computerChoice = Math.random();


if (computerChoice <= 0.33) {
    computerChoice = "rock";
else if (computerChoice <=0.66) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";


the ‘else if’ statement won’t run if less than 0.33 because there is a statement in place for less than 0.33 so the ‘if’ statement overrides the else if statement printing rock instead of paper, also if this principle wasn’t in place it would come up with a error not rock, paper or scissors