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 (Retired) Making Decisions with Conditional Statements Review Conditional Statements and Comparison Operators

Swan The Human
Swan The Human
Full Stack JavaScript Techdegree Student 19,326 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
216,014 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.