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) Introducing JavaScript The Console Challenge Answer

Ruben Tugnolo
Ruben Tugnolo
8,096 Points

Workspaces

Hi! I would need a quick answer. Why I don't see any error in google chrome console when I run this code even if in line 1 and 6 is semicolon missing?

console.log("Start program") alert("Help me fix this program!"); alert("Can you get this message to appear?"); document.write("<h2>My first JavaScript program</h2>"); document.write("<p>I'm practicing 'debugging'.</p>"); console.log("End program")

Thank you.

1 Answer

Daniel Vigil
Daniel Vigil
26,473 Points

The semicolon in JavaScript is used to separate statements, but it can be omitted if the statement is followed by a line break (or there’s only one statement in a {block}). A statement is a piece of code that tells the computer to do something. The semicolon is only obligatory when you have two or more statements on the same line. You can read more here