CodeAcademy says I did 4/9 right even though it doesn't work and I have no idea why


#1

No matter what number I get it returns scissors but code academy say's it's right.

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

#2

Made a post about this here:
https://www.codecademy.com/forum_questions/51fc4178f10c60f4eb001233#answer-529f101f7c82ca3ce100308d

Also no conditions after else. The reason why you can pass is probably because it is hard to check for a random result.


#3

This is the reason. You
computerChoice >= 0.33 and computerChoice <= 0.66


#4

I did this:

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

And it's still not working, it's scissors every time.


#5

So if x>y>z is wrong for some reason, what's the right way? I've looked through all the lessons and I can't find the explanation.


#6

Try this:

var computerChoice = Math.random();
console.log(computerChoice)

if (computerChoice < 0.33){
    computerChoice = "rock";
}else if(computerChoice < 0.66){
    computerChoice ="paper";
}else{
    computerchoice="scissors"
}
console.log(computerChoice)

#7

How does the semicolon work in this case? I see you used it twice, but one iteration I tried was basically what you put here just without the semicolons. I can't seem to find a good expanation in codeacademy about the semicolons too.


#8

Thats because else doesn't have a condition:
https://www.codecademy.com/forum_questions/52373a75548c3515940000dc#answer-529fa36052f863bb58000338


#9

There are 2 options that are pretty common either you go with the boolean operators && (AND) or || (OR) and structur it new x > y && y > z: "x is bigger than y and y is bigger than z"
But as far as I know they're not introduced at this point. Or you think a bit about the range of Math.random. Is it possible to go below 0? No so you don't have to check this case yourself. Is it possible to exceed 1? No,... And last but not least is it possible to not be picked by the first case but still have a value below 0.33?


#10

https://www.codecademy.com/blog/78-your-guide-to-semicolons-in-javascript