Bug in Computer Choice: Part 2 Build "Rock, Paper, Scissors"


<>Please fix the bug

Computer Choice: Part 2 Build "Rock, Paper, Scissors"

if I use { } then the program does not pass, so I removed it and it solved a problem, but if/else if/ if suppose to be with {}

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice <= 0.33) 
    computerChoice = "rock";
  else if (computerChoice <= 0.67) 
    computerChoice = "paper";
  else (computerChoice <= 1) 
    computerChoice = "scissors";


Well, that's an amazing one. So it let you pass without the curly braces? :nerd:

This line isn't complete

You should have

else if (computerChoice >= 0.34 && computerChoice <= 0.67 )

Finally, else should never carry an expression or have a statement to it.

As a summary,

var userChoice = prompt("Do you choose rock, paper or scisssors?");
var computerChoice = Math.random();
if(computerChoice <= 0.33) {
computerChoice = "rock" ;
} else if (computerChoice >= 0.34 && computerChoice <= 0.67 ) {
computerChoice = "paper" ;
} else {
computerChoice = "scissors" ; 
console.log(computerChoice); //this will help you see your choice printed to the screen.

I hope this helps


I wrote it for whoever fixes it. I tried && all this thing from CS101
stanford javascript course just codeacademy program did not let me pass
with any code I used, only after curly brackets were removed, it let me go.
I know from the HTML&CSS course that sometimes bugs won't let you go until
you make some stupid step. Idk if it is a safari. Also from the HTML & CSS
I learned some advisors just a total incompetent. Although always gave them
a good review just for an attempt to help. There are very few of them are
good, knowledgeable.


Woah! Okay...

So we are clear? :wink:


Thank you! Wish to help is a good start!


Good forum!


pretty sure its supposed to look something like this:

var userChoice = prompt("Do you chose rock paper or scissors?")
var computerChoice = Math.random()
if (computerChoice >= 0 && computerChoice <= 0.33)
    computerChoice === "rock";
else if (computerChoice >= 0.34 && computerChoice <= 0.66)
    computerChoice === "paper";
    computerChoice === "scissors";


Thanks to @bayoishola20 for the && section. The use of the &&'s has not even been mentioned in the JavaScript tutorials up to this point, so I was clueless till i saw what he said!


Okay! You're welcome.

Glad I could help. :slight_smile:


Pretty sure the "else if" statement in the code above could be simplified to just:

else if (computerChoice <= .66) {
computerChoice === "paper";

When computerCHoice computes a value of .33 or less the "if" statement is executed and it stops there. if it's > .33 it will move on to the "else if" statement where if it's less than .67 it will stop there.


Has anyone been able to establish why it will only let me pass this part of the lesson when i take out the curly brackets from the if/else if/else statements? Even the hint shows that the curly brackets are supposed to be there but with them in the correct spots I am getting a syntax error message. Only when I take them out will it let me pass onto the next part. Just trying to understand why this is because it seems to be in contradiction with what the lesson is teaching.


Best thing for you to do is start a new topic, paste a link to the exercise, copy & paste all your code and then mention what specific error message you're getting. :slight_smile:


It is mentioned in the Glossary, which is available throughout the course. Use your resources....... :wink:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.