Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements The Conditional Challenge Solution

The Conditional Challenge Solution

I want to ask if its also good way to output rank like that instead of like its showing in solution video?

if (score === 3 || score === 4 || score === 5) {
  document.write("You got golden crown!!! Your score is: " + score);
} else if (score === 1 || score === 2) {
  document.write("You got silver crown! Your score is: " + score);
} else {
  document.write("You didnt get any crown.. :(");
}

I'm not familiar with the video you're referring to, but the only thing I can see that might cause issues down the road is if there are more questions added to where you get more than 5 points, you would get the "You didn't get any crown... :(" response. might be simpler to make it :

if ( score >= 3 ) {
    document.write("You got the golden crown!!! Your score is: " + score)
} else if (score === 1 || score === 2) {
  document.write("You got silver crown! Your score is: " + score);
} else {
  document.write("You didnt get any crown.. :(");
}

1 Answer

Steven Parker
Steven Parker
231,269 Points

By checking value ranges instead of specific numbers, the method in the video helps keep the code compact, and supports possible future modifications (as Jeff suggested):

if ( score >= 3 ) {
    document.write("You got the golden crown!!! Your score is: " + score)
} else if ( score >= 1 ) {

Each test needs no high limit check because the previous "if" would have caught it.

I have only 5 prompt questions so it cant be more than 5 questions. Do you still think I need to use code like Jeff said or if there are no more questions than 5 then I can use my code?

Steven Parker
Steven Parker
231,269 Points

It won't make much difference with only 5 questions and three categories, certainly none that would impact the operation of the program.

But it might be good to develop a practice of using a method that would still be compact and efficient when you had 50 questions and 10 categories.

Okay I understood. Thank you for your reply :)