4, ComputerChoice Pt.2 - Syntax Error


#1

Whats wrong? heres the code exactly

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

`


#2

Refresh the page, then try with this code instead:

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if(Math.random <= 0.33) {
    computerChoice = "rock";
}
else if(0.33 < Math.random <= 0.66) {
    computerChoice = "paper";
}
else {
    computerChoice = "scissors";
}

console.log(computerChoice);

#3

is not right. You should write if(computerChoice<0.34) or if(computerChoice<=0.33)

And you don't have to write console.log after the if condition. Because in the end of your code you will need to print computer choice. Instead doing that you just need call var computerChoice after if condition.


#4

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