Computer Choice part 2


#1

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

var computerChoice = Math.random()

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

Receiving a syntax error and not sure why...


#2

What syntax error are you receiving?


#3

else can't have a condition since its everything else.

Also, if you decide to use the and operator (&&) it would be better to do comparison at both sides of the and operator. You don't even need the and operator.


#4

Thanks, it worked, what do you mean I don't need the and operator though? I fixed it to be (computerChoice > 0.34 && computerChoice < 0.66)


#5

well, why do you need this condition:

computerChoice > 0.34

your if condition takes care of values lesser then .33, i don't see why you you need to repeat it else if. But that is just an optimization.


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.