This forum is now read-only. Please use our new forums! Go to forums

banner
Close banner
0 points
Submitted by Cher Poston
over 10 years

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!

Answer 526ddca580ff3357d6001c0e

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”; }

points
Submitted by Diego Palma
over 10 years

2 comments

mdn0403 over 10 years

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.

Gareth Müller over 10 years

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

Answer 526dde99abf821a43e0069f0

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.

points
Submitted by Cher Poston
over 10 years

Answer 528a6a45f10c603925000405

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.

points
Submitted by mandamarie415
over 10 years