Fixed 4/9 and it's still broken but telling me it's good


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

Scissors every time


#2

This is my code:

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.66) {
    computerChoice = "paper";
}
else{
    computerChoice = "scissors";
}

To say the truth, I have no idea what you did there, for I do not know what && is, and your code is very complicated. But what I do know is that it is not needed. Also, I believe you don't need to put anything in the "scissors" section, and instead just put "else" and computerChoice = "scissors";.

Please use my code as reference. I hope my code helps!


#3

&& stands for the boolean operator and e.g. the statement A && B would only be true if both A and B are true at the same point or as an example of arcwhiz90664's code:

is true when computerChoice is smaller than 0.33 (you can omit the leading 0) and if computerChoice is bigger than 0. So basically we use this operator to chain conditions to a bigger one.

But you're right one does not need it at that point. And your also right with the other point:

The problem results from using a "condtion" after else. But else has no condition as it is the default case. I wrote a longer post over here covering conditions and you should be able to extract why this is a problem:

https://www.codecademy.com/forum_questions/52373a75548c3515940000dc#answer-529fa36052f863bb58000338

if not feel free to ask.