The wrong result is returned (i.e. paper instead of scissors) in the 1 part


#1

https://www.codecademy.com/en/courses/javascript-beginner-en-Bthev-mskY8/0/4?curriculum_id=506324b3a7dffd00020bf661#

actually no errors are found in code, BUT the problem is that the result that is returned is not right. As seen on the screenshot below it returns "paper" instead of "scissors" when computerChoice is bigger then 0,76

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

#2

That's because your else if statement should have multiple conditions.


#3

I believe this is the case because instead of 0.67 you have 0,67.


#4

As far as I understood the conditon is written fully, because:
var computerChoice = Math.random(); // this means that the variable computerChoice is (0;1)
so as a result the condition for else if should be just >=0,67, knowing that it is less then 1 a priori.

Either way when making a multiple condition it doesn't work right as well


#5

You. Are, Amazing, I ADORE ppl who are so attentive to details!))))) Oh my gosh, now it's me sitting here, blushing and feeling stupid.... :grinning: THANK YOU A LOT! :slight_smile: You're genius!


#6

No problem lol I make mistakes like that all the time haha I think half my questions on the forum have been spelling errors xD Hope the rest of your coding goes well! :smiley:


#7

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