Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics Making Decisions in Your Code with Conditional Statements The Conditional Challenge Solution

Xun Huang
Xun Huang
Web Development Techdegree Student 10,462 Points

It's always 0 when I use "||" instead of ">=" .

here's my code:


  1. Rank player based on number of correct answers
    • 5 correct = Gold
    • 3-4 correct = Silver
    • 1-2 correct = Bronze
    • 0 correct = No crown */

if (correct === 1 || correct === 2){ rank = "Bronze" }else if(correct === 3 || correct === 4){ rank = "Silver"
}else if (correct === 5){ rank = "Gold" }else { rank = "None :(" }

Could someone tell me why?

1 Answer

Your code runs fine on my end. Have you counted the correct answers?

However, the codes could also be refactored with a switch statement when there's too many if statements involved:

let rank;
// play with this variable to see different results
let correct = 5;

switch (correct) {
    case 5:
        rank = "Gold";
    case 4:
    case 3:
        rank = "Silver";
    case 2:
    case 1:
        rank = "Bronze";
        rank = "No crown";