Computer choice part 2


#1


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


Oops, try again.
There was a problem with your syntax.


I have tried this:

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

And this:

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


Still get the same error. Tried rewriting as well. Could use some help.

Thanks


#2

Hello

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);

Maybe try this, I am also new to Javascript.


#3

Hey

Thanks. That works. Still would like to understand why it gives me the syntax error. Even if the condition is wrong.


#4

Oh now I got it. I was missing ; at the end of var userChoice = prompt("Do you choose rock, paper or scissors?")


#5

What is the differences between our codes?
It is hard to compare, I do not have two consoles next to each other.


#6

So syntax means all the brackets, semi-colons, etc. OK was not sure if it meant the same as in java.
I know they are not the same coding. Glad I could help.


#7

I am going to be honest with you - it is amazing how different code languages can have things in common. It is just remembering the rules that set them apart.


#8

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