This forum is now read-only. Please use our new forums! Go to forums
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
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”; }
Answer 526dde99abf821a43e0069f0
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.
Answer 528a6a45f10c603925000405
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.
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
2 comments
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.
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