Computer Choice part 2, unexpected token {, what has gone wrong?


#1

SyntaxError: Unexpected token {

var userChoice = prompt("Do you choose rock, paper or scissors?")
var computerChoice = Math.random();
console.log (computerChoice);
if (computerChoice <= 0.33) {
computerChoice == "rock";
}
else (computerChoice <= 0.66){
computerChoice == "paper";
}
if else {
computerChoice == "scissors";
}


#2

Hi the structure should be like that

if (condition) {

}

else if (condition) {

}

else {

}

#3

Thank you so much it works now, yay!


#4

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
console.log(computerChoice);
if (computerChoice <= 0.33) {
computerChoice == "rock";
}
if else( computerChoice <= 0.66) {
computerChoice == " paper";
}
else {
computerChoice == "scissors";
}

Problem with syntax =-=. pls help me


#5

Hi try to change your if else by else if

#6

Why is computerChoise == and not ===. I thought it was always ===. Please help me because I don't know the answer


#7

I believe it can be either one, I got it to work with == so I don't know.


#8

== checks the values
=== checks the values and the types


#9

when i type this in I get "Unexpected token illegal"...any solutions?

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
{ 
    if(computerChoice <=1) 
        computerChoice=="Scissors";
    };

#10

As you can see by the odd color after formatting the code the error is using different kinds of quotes so it expects the rest of your code to belong to this string as well.

Also pretty interesting idea for the else if in the last case but not really necessary as Math.random is always less than 1. Also do you know why you can, under certain circumstances, omit the {} for the if?