Computer Choice : Part 2


#1



https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/0/4?curriculum_id=506324b3a7dffd00020bf661#


SyntaxError: Unexpected token <=


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

var computerChoice = Math.random();

console.log(computerChoice)

if (computerChoice = 0 && <= 0.33); {
    computerChoice = "rock";
    
    
} else if (conputerChoice = 0.34 && <= 0.66) {
    computerChoice = "paper";
    
    
} else (computerChoice = 0.67 && <= 1) {
    computerChoice = "scissors";
    
};


#2

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.


#3

still not working.

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

var computerChoice = Math.random();

console.log(computerChoice)

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

#4

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

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


#5

Not only is there a typo as @barbaraaax has said, but there's also a semicolon (;) where there shouldn't be one:


#6

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 http://www.w3schools.com/js/js_comparisons.asp if you want to know more.
and sorry for the horrible grammar.


#7

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();

console.log(computerChoice);

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

#8

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