SyntaxError: missing before statement


#1

I have tried to let the computerChoice return rock, paper or scissors but I keep getting this error

var userChoice = prompt("Do you choose Rock, Paper or Scissors?");
var computerChoice = Math.random() {
    if (computerChoice <= 0.33) {
    return "Rock"
    } else if (computerChoice > 0.33, < 0.66) {
    return "Paper"
    } else (computerChoice > 0.66 ) {
    return "Scissors"
    }
}


#2

HI the else statement doesn't take any condition

if (condition) {

}
else if (condition) {

}

else {

}

#3

This is not a valid JavaScript statement and should throw an exception, such as "Unexpected token ',' " or some such.

We don't need to make a logical expression in this case, just a single comparison.

Eg. if ( c < 0.67 )

When we have a situation where we need to write a logical expression, we compare both operands in separate expressions to make up the whole:

Given A, B and x:,

if ( A < x && x < B )

In the above both expressions must yield true else the entire expression will yield false.


#4

I sill get the same error. I'm not sure if I understood properly, but here's my new code.

var userChoice = prompt("Do you choose Rock, Paper or Scissors?");
var computerChoice = Math.random() {
    if (computerChoice <= 0.33) {
    return "Rock"
    } 
    else if (computerChoice > 0.33 && computerChoice  < 0.66); {
    return "Paper";
    } 
    else {
    return "Scissors";
    }
}

#5

HI this line try to remove the ;

else if (computerChoice > 0.33 && computerChoice < 0.66); <--

#6
var userChoice = prompt("Do you choose Rock, Paper or Scissors?");
var computerChoice = Math.random() {
    if (computerChoice <= 0.33) {
    return "Rock"
    } 
    else if (computerChoice > 0.33 && computerChoice  < 0.66) {
    return "Paper";
    } 
    else {
    return "Scissors";
    }
}

Still


#7

that

var computerChoice = Math.random()

isn't a function so remore the { } around the if else if and else statement

And

inside you if, else if and else statement instead of return you should set compuChoice

like that for the if statement

if (computerChoice <= 0.33) {
    computerChoice =  "Rock";
} 
....

#8
var userChoice = prompt("Do you choose Rock, Paper or Scissors?");
var computerChoice = Math.random() 
    if (computerChoice <= 0.33) {
    return "Rock"
    } 
    else if (computerChoice > 0.33 && computerChoice  < 0.66) {
    return "Paper";
    } 
    else {
    return "Scissors";
    }

same error


#9

Read my post after And


#10

YESS! It worke, finally. Thank youu!
var userChoice = prompt("Do you choose Rock, Paper or Scissors?");
var computerChoice = Math.random()
if (computerChoice <= 0.33) {
compouterChoice = "Rock"
}
else if (computerChoice > 0.33 && computerChoice < 0.66) {
computerChoice = "Paper";
}
else {
computerChoice = "Scissors";
}


#11

Now I cant get over this syntax error. I tried debugging it myself but I can't seem to find any solution.

    var userChoice = prompt("Do you choose Rock, Paper or Scissors?");
    var computerChoice = Math.random();
    if (computerChoice < 0.34) {
        computerChoice = "Rock";
    } else if(computerChoice <= 0.67) {
        computerChoice = "Paper";
    } else {
        computerChoice = "Scissors";
    } 
    console.log("Computer: " + computerChoice);
    var compare = function (choice1, choice2) {
        if(choice1 === choice2) {
            return "The result is a tie!";
        }
        else if (choice1 === "Paper") {
            if (choice2 === "Rock") {
                return "Paper wins";
            }
            else {
                return "Scissors wins";
            }
        }
         else (choice1 === "Scissors") {
             if (choice2 === "Rock") {
                 return "Rock wins";
             }
             else {
                 return "Scissors wins";
             }
         }
    };

#12

This line

else (choice1 === "Scissors")

you wrote else instead of else if


#13

It solved the problem. But, I already wrote an if and else if that's why I wrote an else


#14

that isn't a if , else if and else statement because in this case since you need to put condition you wont use the else satement but something like that

if (condition) {

}
else if (condition) {
  #here you put the if and else statement
}
else  if (condition) {
    #here you put the if and else statement
}
else if (condition) {
    #here you put the if and else statement
}