I dont see an error


#1

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

This javascript


#2

is it telling some kind of a error?


#3

i figured it out for ya
there you have written CONPUTER in line 6 and in line 6 and line 8 choice is written choise
try to fix that


#4

You have wrong conditions for if/else if/else statement:

if(computerChoice = (0 < 0,33)){
  console.log("rock");
} else if (conputerChoise = (0,34 < 0,66)){
  console.log("paper");
} else(computerChoise = (0,67 < 1)){
  console.log("scissors"); 
}

Condition should be an expression that is considered to be either truthy or falsy. In your case

(0 < 0,33)
(0,34 < 0,66)
(0,67 < 1))

all of them returns true. Also you used assign operator =. So how it works now:

if(computerChoice = true){
  console.log("rock");
} else if (conputerChoise = true){
  console.log("paper");
} else(computerChoise = true){
  console.log("scissors"); 
}

Now if you run the code you will see that the 1st value computerChoice should be between 0 and 1. But this variable reassigned in if conditions and your statement looks like:

if(true){
  console.log("rock");
} else if (true){
  console.log("paper");
} else(true){
  console.log("scissors"); 
}

As a result you should have

"rock"
"paper"
"scissors"

Don't you?
Now lets try to do some corrections. As I said, condition should returns true or false. But this condition has to be an axpression. For this goal we need to use comparison operators like > < == ===:

if (computerChoice <= 0.33) { ... }
if (computerChoice > 0.33 && computerChoice  < 0.67) { ... }
else { ... }

Also be careful with variables using. You defined variable conputerChoice, so you need to use exectly the same name, because conputerChoise is not defined.


#5

WOW!!!! Thank you! fine


#6

Nice sorry ok i understand


#7

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