Build "Rock, Paper, Scissors" Error


#1

Hey, I cant seem to find the error, please help me.

var userChoice = prompt("Do you choose rock, paper or scissors?")
var computerChoice = Math.random();
console.log(computerChoice)

if (computerChoice <= 0.33) {
    computerChoice = "rock";
} 
else if (computerChoice = .34 && computerChoice <= 0.66) {
    computerChoice = "paper";
} 
else (computerChoice >= 0.67) {
    computerChoice = "scissors";
}


#2

var userChoice = prompt("Do you choose rock, paper or scissors?"); //missing semicolon here
var computerChoice = Math.random();
console.log(computerChoice); //missing semicolon here as well

if (computerChoice <= 0.33) {
computerChoice = "rock";
}
else if (computerChoice == 0.34 && computerChoice <= 0.66) { //you NEED to have 0.34 not just .34. Error message: "A leading decimal point can be confused with a dogt: '.34'. Assignment in conditional expression". The last part of that error is regarding your equal signs. computerChoice = 0.34 is a var assignment. You want computerChoice === 0.34, so on and so forth. == also apparently works though.
computerChoice = "paper";
}
else { //an else statement takes no conditions. Else means everything else. So either make another else if here or just take out the condition entirely; computerChoice >=0.67 is unnecessary, in otherwords.
computerChoice = "scissors";
}

//else should look like else {what you want the code to do;} with whatever formatting you want.

Compare the updated code I have here with your own code to see the exact differences. Hope this helps!

A fantastic resource for linting is https://repl.it/languages/javascript
Slap your code into that and it'll tell you as much as it can about what's wrong.


#3

You can also change the else if condition outright to (computerChoice<=0.66).


#4

Ahh duh, thank you guys so much.


#5

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