Javascript Syntax error


Trying to figure what i did wrong, also the instructions say if number is between 0 and 0.33 I'm not sure if the comparison operator i used is the right one:

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random()
if (computerChoice 0 >= 0.33) {
    return computerChoice = "rock";
else if (computerChoice 0.34 >= 0.66) {
    return computerChoice = "paper";
if (computerChoice 0.67 >= 1) {
    return computerChoice = "scissors";


The SemiColon Always tricks you

You didnt put a semi Colon after

var computerChoice = Math.random()

That caught my eye way too quick than usual :laughing:


This does not work. What you need to do here is to check if computerChoice is less than 0.33 (it's greater than 0 anyway because of the range of Math.random so maybe ignore this for now and just focus one the important boundary.)


hmm thanks for the input, but that didnt fix the problem


here are the instructions:

If computerChoice is between 0 and 0.33, make computerChoice equal to "rock".

I am not sure how this is suppose to look in code. Meaning what comparison operators mean "between"?


Follow haxor789's Lead if mine dosent work


yeah im confused as to how i check computerChoice when the value changes everytime


Here is the code:

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

var computerChoice = Math.random();

if (computerChoice<=0.33) {
} else if ((computerChoice>=0.34) & (computerChoice<=0.66)) {
} else {

but the only diffrence you had to make is change print the user and computer input. Reply to me if it dosent work. :smile:


that worked thanks. Just to clarify, you put (( on ELSE IF because there were two conditions, right?


By conditions if you mean like if statements yes, but if you mean like by coditons i had both if computerchoice >=0.45 and <==0.66 then no.


What @haxor789 means is that in this case, Math.random only picks a random number between 0 and 1. That means that you don't have to say that if the number is between 0.33 and 0, for it would already show how it is. If this is a hard explanation, I will show you with a picture:

Let's say that this is how Math.random is used, like pulls a random number out of it.

Now, you only need one condition to show between 0 and 0.33.

See that there's only one red line? But it shows the area between 0 and 0.33.

Now to separate that with 0.67, you also only need one line, because it is with 0.33 already.

See that there's only two red lines that are needed to separate 0 to 1 into 3 parts? That's how you use the if, else if, and else loop. :smiley:


@amanuel2 Has already shown the code, and he had put two conditions for the else if loop, which is also a fine way of doing it. But you can read this. :smiley:

But another good way is:

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


Wow you did all this lol?


ok maybe this will help me explain, I tried just experimenting for my own knowledge by adding:

else ((computerChoice >=0.67) & (computerChoice <=1)) {

it didnt work.


wow haha thanks for this detailed explanation


Uhh... yeah. I was making the drawings and when I came back, it seemed that you have already given the code. I was like "Whoops. Uhhh..."


Hey @objectmaster13146,

That's an else loop. :smiley:

Else loops don't include conditions, remember? :smiley:


ahh thanks that helps a lot. And no i dont remember lol


You will remember Next time!


About this:

else if ((computerChoice>=0.34) & (computerChoice<=0.66)) {

On @objectjumper63431 masters question about the ((:
Yes the (( result from the two conditions but it's not like two conditions require two (. If you have a close look you see that it is still

else if(...)

but @amanuel2 put a pair of () around the two conditions:

else if (   (computerChoice>=0.34)    &   (computerChoice<=0.66)   )

If you have a look at:
You could see that >= and <= already have a higher priority than & so the () around the statements are not really needed, but I had to look it up myself and you're save to have the right order of execution when you use them.

Last but not least @amanuel2 the & is the the binary AND-Operator better use the boolean operator && instead.

The way & works is something like this:

1 | 1 | 1 = 7
1 | 0 | 0 = 4
1 | 0 | 0 = 4

So in this example 7&4 -> 4 because the boolean AND- Operator just keeps those digits as one where both were 1 in the original numbers.
As booleans have a numerical value of 0 and 1 as well this also works here but it's really made for other purposes and it's better to use &&.


That still confuses me lol. The 2-bit thingy :smiley:

But I GET IT NOW! (kinda)