Looking for help with "Build 'Rock, Paper, Scissors'" syntax. Can anyone help me?


#1

I can't figure out what is wrong with my code. I keep getting the error message: "SyntaxError: Unexpected token {" Here it is:

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

var computerChoice = Math.random(){

if(computerChoice < 0.34){
computerChoice = "rock"
}

else if(computerChoice =< 0.66){
computerChoice = "paper"
}

else(computerChoice =< 1){
computerChoice = "scissors"
}


#2

after you var computerChoice = Math.random() you put a "}" instead of ;


#3

Sorry, that didn't work. Any other ideas?


#4

Sorry, it did work, (that error was solved), but now there is a new error that says: SyntaxError: Unexpected token <. Here is the code:

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

var computerChoice = Math.random();

if(computerChoice < 0.34) {
computerChoice = "rock"
}

else if(computerChoice =< 0.66) {
computerChoice = "paper"
}

else(computerChoice =< 1) {
computerChoice = "scissors"
}


#5

@wizmarco was right but there is another problem:

else(computerChoice =< 1) {

else has no condition. Either make it else if for a specific condition or deleted the condition than else handles everything that is not handled by the previous if and else ifs.


#6

yes that is because on the slse if statement you put (computerChoice =< 0.66) insteat of (computerChoice <= 0.66)
and like @haxor789 say the else should'nt have a condition so it should be like that

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

var computerChoice = Math.random();

if(computerChoice < 0.34) {
computerChoice = "rock"
}

else if(computerChoice <= 0.66) {
computerChoice = "paper"
}

else { 
computerChoice = "scissors"
}

#7

This worked perfectly! Thanks so much!