Why did this work (Computer Choice Part 2 answer)?


#1

Hey, everyone. I just completed "Computer Choice Part 2" and I got it correct but I want to know if it was an error. I'm asking because I have noticed that sometimes the right answers are flagged as wrong. Now I fear the wrong answers may be accepted as correct (what a way to live). Was my initial code correct (specifically referring to the "else if" statement)? Is the syntax off?


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


#2

The following line:

else if (0.34<= computerChoice <= 0.66) {

is wrong. Read here for why it is wrong.


#3

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