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

Any tips or recommendation on what I could do to improve this code based on the current or previous lesson.

Here's the link to the code https://w.trhou.se/v2npyjd99l

I know there are ways to improve the code using more advance techniques but I haven't learned them so mentioning an advance technique isn't going to help me right now instead it just going to confuse me with trying to understand why it's better.

But based on the current and previous lessons, please feel free to share any inputs that could help me out.

  1. I noticed in a lot of the other codes students have posted that people are using the && and instead I thought it would be easier to use || and so I did in my code. Was that the best call in this situation?

  2. Should I had included a console.log... Once again I saw codes that included but I don't understand why it would be needed so I didn't included. Is there a reason why I would need to include it?

  3. Did I provide enough detailed comments to make the code readable?

Feel free to include anything else I may have missed.. Thank you

Simon Coates
Simon Coates
28,694 Points

1) console.log prints messages to the console. to the end user, these are usually invisible.

2) could you could use > in the conditionals, and have the final condition be an else rather than an else if. Logically, if the counter isn't 1, 2, 3, 4, or 5, it's implicitly 0.

1 Answer

I don't know but I'll try switching it to the > and see what happens. I used the else if because it was the last thing we learned but I didn't consider doing the code using just else.

And thanks for the info about the console.log

Simon Coates
Simon Coates
28,694 Points

There's nothing too wrong with your code, apart from using the advance features (functions), which just eliminate duplication and make the code shorter and more manageable. The else stuff doesn't matter too much. It was just an observation that in this instance, the variable being tested has limited variation and one test might be deemed better than two. something like:

if (score === 5) {
  document.write("<strong>Congratulation!</strong> You've earn the GOLDEN CROWN PRIZE!");
} else if (score > 2) {//not five, but greater than 2.
  document.write("<strong>Great Job!</strong> You've earn the SILVER CROWN PRIZE!");
} else if (score > 0) {//not five, not greater than two, but greater than 0.
  document.write("<strong>Nice Try!</strong> You've earned the BRONZE CROWN PRIZE!");
} else  {//none of other conditions are met - score is 0.
  document.write("<strong>Sorry!</strong> You did not win any prizes today. Try again later.");
}

I also added semicolons to the end to each document.write statement, though the javascript interpreter didnt' seem to care.