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!

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 Review Conditional Statements and Comparison Operators

Swan The Human
Swan The Human
Full Stack JavaScript Techdegree Student 19,338 Points

The lesson said you don't need a semicolon in Conditional Statements but in this challenge they are there. Enlighten me?

In one of the previous lessons teaching conditional statements, it said you didn't need to have semicolons. Now in this code challenge they are there after the if and else statements. I'm not sure if it just meant after the curly braces closing out the if else statements or all together including alerts/document.write, etc. Any extra info or explanation would be greatly appreciated!!!


1 Answer

Steven Parker
Steven Parker
228,095 Points

Semicolons are actually optional after statements, but it's "best practice" to use them anyway.

But a code block contains statements between two braces, it's not a statement itself, so you don't put a semicolon after one. If you look closely at the quiz examples, I think you will see that the semicolons are at the end of statements inside the blocks, not after the blocks themselves.