Help! I dont know whats wrong, unexpected number?


#1

var userChoice = prompt("Do you want to choose rock, paper or scissors?")
var computerChoice = Math.random()
console.log(computerChoice);
if(computerChoice 0 < 0.33)
{
    var computerChoice = function("Rock")
}
else if (computerChoice 0.34 < 0.66)
{
    var computerChoice = function("Paper")
}
else (computerChoice 0.67 < 1)
{ 
    var computerChoice = function("Scissors")
}

Help!!!


#2

Hey @boardrunner71238! You dont needed to put a number in front of computerChoice! I will show you one part and you do it to the rest of them. So for example instead of your code here:

do this:

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

And the other thing is that once you created a variable you dont need to create t over and over again, plus you dont need a functionto set it equal to something you just set it equal to! I hope this helped!


#3

As @amanuel2 already mentions instead of writing a function just assign a value. I guess it's "rock" instead of "Rock" but this is probably mentioned in the description. Also this was not how functions work so better review this chapter or ask if there were any questions as you need to write a function in this chapter as well.

The other thing is this condition:

if(computerChoice 0 < 0.33)

doesn't work as well in short:

missing operator between those two : computerChoice 0
missing operator between those two: (computerChoice) (0 < 0.33)

and don't think about computerChoice< 0 < 0.33 this doesn't work as well. Better think about if computerChoice could even be below 0. For example:

if(computerChoice< 0.33)

Last but not least there is no condition after else as else is the default case.

PS: @amanuel2 What does this mean?

And the other thing is that once you created a variable you dont need to create t over and over again


#4

It means that once you created/initated a variable like this:

var something;

you dont need to create it again when you compare it for example like this:

var something>8;

Instead do this

something>8

#5

Oh of course :smile: . Completely missed that.


#6

thank you, it is now saying unexpeted string/syntax error

var userChoice = prompt("Do you want to choose rock, paper or scissors?")
var computerChoice = Math.random()
console.log(computerChoice);{
{
if( 0 < 0.33)
{
computerChoice = function("Rock")
}
else if (0.34 < 0.66)
{
computerChoice = function("Paper")
}
else ( 0.67 < 1)
{
computerChoice = function("Scissors")
}};


#7

Hey @boardrunner71238. I said previously dont do computerChoice = function("Rock"), instead to set it equal to just do computerChoice = "Rock";


#8

Maybe have a look at this how if and else work and why you use {}: