4. Computer Choice: Part 2 Pleaseeee Help


#1



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


I keep getting
SyntaxError: Unexpected token >=

I'm sure it's just something small that I'm missing, but I just can't figure out what I'm doing wrong.


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 = >= 0.67)
{
    computerChoice = "scissors";
}
};


#2

else can not have any conditions attached to it.


#3

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 >= 0.67)
{
computerChoice = "scissors";
}
};

Okay, so now it reads as this but I'm still getting a syntax error


#4

I'm not sure what you changed there, but else can not have ANY conditions attached to it.


#5

Ahhhhhh

Thank you so much finally got it

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

var computerChoice = Math.random ()
if (0<=computerChoice<=0.33) {
computerChoice = "Rock";}
else if (0.33 computerChoice = "Paper";}
else {computerChoice = "Scissors" }
console.log (computerChoice)


#6

if (0<=computerChoice<=0.33) 
if (0.33 computerChoice = "Paper";}

Those two lines have problems.

JavaScript has no "between" comparison as you have done on the first line.

The second line, well, I'm not sure what you want that one to really say -- but if you look back at your first try, you'll see how it should be.


#7

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 {computerChoice = "Scissors" }
console.log (computerChoice)

Think I got it. It still ran the other way for some reason. Thanks for the help.


#8

You are welcome for the help.

It ran because the code didn't have any syntax errors, BUT if you did some testing you would quickly find out that the results from that code would not be what you expected.


#9

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