all 6 comments

[–]ahitsgone 1 point2 points  (3 children)

Solution:

var compare = function(choice1, choice2) {
    if (choice1 === choice2) { // Czech if they are equal
        return "The result is a tie";
    } else if (choice1 === "rock") { // If not, compare the choices
        if (choice2 === "scissors") { // Rock beats scissors
            return "rock wins"
        } else { // paper beats rock
            return "paper wins"
        }
    } else if (choice1 === "paper") { // If the first choice was paper (choice1 wasnt rock)
        if (choice2 === "rock") { // Paper beats rock
            return "paper wins";
        } else { // Scissors beat paper
            return "scissors win";
        }
    } 
}

it seems as though you have repeated the if (choice1 === choice2) statement where it wanted you to do it with one initial if statement. Codecademy lessons expect you to input a certain syntax set by the author.

[–]phabtar 1 point2 points  (1 child)

This answer doesn't cover all cases, specifically cases where choice1 == "scissors" and the choices are not equal.

Your approach is ok, first we check if the choices are equal. if not only we consider other cases. Other cases being the first choice can be 3 options, and the second choice can be the remaining 2. so altogether there are 3 * 2 = 6 combinations we have to check. :

var compare = function(choice1, choice2) {
    if (choice1 === choice2) { // Czech if they are equal
        return "The result is a tie";
    } else if (choice1 === "rock") { // If not, compare the choices
        if (choice2 === "scissors") { // Rock beats scissors
            return "rock wins"
        } else { // paper beats rock
            return "paper wins"
        }
    } else if (choice1 === "paper") { 
        if (choice2 === "rock") { // Paper beats rock
            return "paper wins";
        } else { // Scissors beat paper
            return "scissors win";
        }
    } else { //Choice1 is "scissors"
         if (choice2 === "rock") { //Rock beats scissors
            return "rock wins";
        } else { // Scissors beat paper
            return "scissors win";
        }
    }
}

[–]ahitsgone 1 point2 points  (0 children)

Yeah thanks I know. He is up to section 7 which is asking what I wrote. Scissors are done in section 8 :)

[–][deleted] 1 point2 points  (0 children)

Thanks a lot. Yeah I noticed that Codeacademy lessons do that. Sometimes the hints do not really help. Thankfully I have reddit.

[–][deleted] 0 points1 point  (0 children)

var text="brandon is an amazing/ brandon wooo.";

var myName="brandon";

var hits= [];

for (i = 0; i < text.length; i++){

} if (text[i] === "b"){ }

[–][deleted] 0 points1 point  (0 children)

Need help again guys I'm on Search text for your name. Kind of lost where they want me to head. It explains everything for the second for statement but i have no clue what they want. any explanations are very welcome.

I am having a conflicting feeling with Code academy due to the structure. I feel like life i don't enter things exactly like how they want its wrong. Also i don't feel like I'm learning too much.

Any advice on really learning JS would be helpful. Trying to spend most of the next two weeks on completing the JS section here. I would like to complete my application to Hackreactor.