This forum is now read-only. Please use our new forums at discuss.codecademy.com.

280 points
523ecca380ff337ae40018fd_869408220
Submitted by
Cher Poston
over 5 years ago

Please look at my Code

So I tried this and it keeps telling me that there is something "not quite right" with my code. Can someone please look at this and tell me what I'm not doing right. I am super frustrated.

var userChoice = prompt("Do you choose rock, paper, or scissors?");

computerChoice = Math.random();
console.log(computerChoice);
if (computerChoice<=.33)
{
computerChoice("Rock");
}
else if(computerChoice >= 0.34 && computerChoice <=0.66)
{
computerChoice("paper");
}
else(computerChoice >=0.67 && computerChoice<=1);
{
computerChoice("scissors");
}

The error message isn't saying that it's a syntax issue, so I'm stumped. Please help!


0 votes

permalink

Hi Cher,
Try the following code

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

if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}

456 points
523f2fa3abf821cdd5002a15_750054492
Submitted by
Diego Palma
over 5 years ago

2 Comments

F333932b3ad6bf15cfd0566f6c1654ae?s=140&d=retro mdn0403 over 5 years ago

How would you write "computerChoice being between .33 and .67"?

with your code, Diego, my logic would tell me that a random number of 0.5 could be rock or paper.

55553075e39efe06930001d3_54591551 Gareth Müller over 5 years ago

Hi mdn0403. I understand what you mean as I had a similar thought. The random number the computer brings up will first check if the first (if) statement is true, if it is it will be equal to "rock" and will ignore the following two if statements. If the computerChoice is higher than .33 it will bypass the first (if) statement as it finds it incorrect and move on to the second (else if) statement, which it will find correct and will be equal to "paper" and will ignore the first and third (if) statement. Hope this answers your question


0 votes

permalink

Thank you. I think it was how I wrote out the code for computerChoice. I am working hard on knowing what to put when and how to write out the codes. It's like learning Algebra.

280 points
523ecca380ff337ae40018fd_869408220
Submitted by
Cher Poston
over 5 years ago


0 votes

permalink

Since no one really answered your question, but instead gave alternatives, I'm going to try. It seems that the problem is that in your last line,

"else(computerChoice >=0.67 && computerChoice<=1);"

it either should have said, "else if" before the condition or just "else" without a condition.

84 points
52893c99f10c607fcf0006ba_823888690
Submitted by
mandamarie415
over 5 years ago