4 computerChoice, part 2


#1

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

console.log(computerChoice = Math.random());

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

but gives "unexpected token {" with:
var userChoice = prompt("Do you choose rock, paper or scissors?");

console.log(computerChoice = Math.random());

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

However this unexpected token is the last "{" from experience

Thank you for your insight, holding on


#2

Hi @cssmaster12593

You just have to add if after your else (he needs if because he has a condition)

else if(computerChoice > 0.67)

Hold on :wink:


#3

@onepunch_man dude... You've got other people saying it now!

@cssmaster12593, a couple things.

1) If statements need to be compared to one value at a time. Like this:

if (computerChoice < 0.34) { ... }

Don't overcomplicate things, think of it like this. Your if, else-if statements will only interact with the first "if" that is determined as true. So let's take a look at the following.

if (computerChoice < 0.34) { ... }
else if (computerChoice < 0.67) { ... }

if computerChoice was 0.27 it would be true in the first if statement, but because the second if statement is an "else-if" it won't run through the code for your second if statement. Just the code in the "if" statement if that makes sense!

--EDIT--
When utilizing more conditions than one per variable you confuse the console. All it sees is comparisons and determines whether or not they're true or false.
--/EDIT--

This isn't just my opinion either, the way you do it the computer sees this.

if (0 < computerChoice < 0.33) { ... }
// ((true || false) < 0.33) { ... }
// ((true || false) || true) { ... }

Basically this whole statement doesn't make sense to the user, and will not feed you correct results.


2) else statements utilize no arguments. Example:

else { ... } //This statement is for ANYTHING that doesn't go in the if statements!

#4

Oh yes ! I forget 0 < computerChoice < 0.33 :sweat_smile: