Computer Choice part 2


#1

What the heck is an identifier?
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random()
console.log(computerChoice)
if computerChoice = 0 to 0.33{
computerChoice = rock
} else if computerChoice = 0.34 to 0.66{
computerChoice = paper
} else {
computerChoice = scissors
}
I apparently have an unexpected identifier. So I am confused,


#2

For your reference, here's the syntax of if elseif else statement in javascript

if(condition here){
      console.log("statement here");
    }
elseif(condition here){
      console.log("statement here");
    }
else{
      console.log("another statement here");
    }

There are problems in our if else condition.

you need to write your if condition like this

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

Place your condition inside a parenthesis, like this if(computerChoice < 0.34) meaning if computerChoice is less than 0.34 (numbers 0.33 to 0). And also, put a double qoute on your string rock, computerChoice = "rock".

Check out my whole codes below, for your reference too. Dont just copy and paste it, analyze it too :slightly_smiling:
);

var computerChoice = Math.random();
    console.log(computerChoice); // print out the random number for computer choice

if (computerChoice < 0.34) {
	computerChoice = "rock";
}
else if(computerChoice <= 0.67) {
	computerChoice = "paper";
}
else {
	computerChoice = "scissors";
}

console.log("Computer: " + computerChoice);

#3

Now, I have another problem on the same exercise: var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random()
console.log(computerChoice)
if (computerChoice = 0 =< 0.33){
computerChoice = ("rock");
} else if (computerChoice = 0.34 =< 0.66){
computerChoice = ("paper");
} else {
computerChoice = ("scissors");
}
console.log("Computer:" + computerChoice);

ReferenceError: Invalid left-hand side in assignment; What is this?


#4

write your if elseif statement like this

if(computerChoice < 0.34)

and

else if(computerChoice <= 0.67)

instead of

and


#5

Thanks! <3! It works now!