I'm stymied! What am I doing wrong?


#1

Ok, I aM on "Rock, paper, scissor" Part 2 - I have spent the better part of two days trying to figure this out.

Here is what I have. I have tried no less than 50 variations, but still can't get it to work. What's wrong?

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


#2

You got many errors. When you do if statements here is what it should look like...

if (statement) {
... code
} else if (statement) {
 ... code
} else {
 ... code
};

Anyway, here is the code you should have...

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

#3

I get you're frustrated. But @steve80 has got the answer. Now it may not make sense to you, because if it's less than 0.33 then it's also less than 0.66 and that's confusing, right? I don't know why it works, it just does. I'm still a beginner like you. But I help where I can and also encourage people when their problems are already solved. So keep going!!! :wink:


#4

It works! Yay. The sloppy coding was largely resulting from me trying numerous different configurations, thinking I was missing something. The big problem was the parameters as you said. In fairness, I think the tutorial could have made some mention of your point (that setting the >=0.33, but not the >=O) was good enough. But all's well that ends well. Thanks.