4. Computer Choice, Code Seems Correct


#1

Hello, I just cannot figure out what is wrong with my code. You will find what I have wrote below.

var userChoice = prompt("Question")
var computerChoice = Math.random()
console.log(computerChoice)
if (0 < computerChoice < 0.33) {
computerChoice = "rock";
}
else if (0.34 < computerChoice < 0.66) {
computerChoice = "paper";
}
else (0.67 < computerChoice < 1) {
computerChoice = "scissors";
}


#2

you're missing a few semicolons - after prompt("Questions"), Math.random(), and next line after console.log.

also, else statements don't have conditions. the right syntax for it is:

else {
    code here
}

i'd also use "===" rather than just "=" when you're checking for equality.


#3

In each of your evaluations, you're using dual comparisons...so you're saying if 0 is less than computerChoice which is less than 0.33. This is confusing.

Cleaner comparison would be:
if (computerChoice < 0.33) {
Do this
else if (computerChoice >= .67) {
Do that
else {
third option
}


#4

OHH!!!! Ok, I made this way too complicated.


#5

It's actually not only "confusing" but is really a nasty bug as it doesn't throw an error but also doesn't do what it is supposed to do. Tried to explain it here a bit longer:
https://www.codecademy.com/forum_questions/51fc4178f10c60f4eb001233#answer-529f101f7c82ca3ce100308d


#6

Much better explanation than I gave. lol.