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 Review Else If Clauses and JavaScript Comments

2 Answers

Ari Misha
Ari Misha
19,323 Points

Hiya there! Everything that comes between "{ }"(curly braces) is a code block. And doesnt matter how many "if" and "else if" you have in your code , only one code block gets run. Conditional statements decide the flow of your application. They make decision for ya and everything statement in code block gets executed. I hope it helped. (:

Christopher De Lette
Christopher De Lette
Courses Plus Student 7,139 Points

Didn't see your posting Ari as i was composing my answer too. You explained it to perfectly :)

Chris

Enemuo Felix
Enemuo Felix
1,895 Points

Thanks Chris and Ari for the help. I will really appreciate if you can explain this statement by Ari better "And doesnt matter how many "if" and "else if" you have in your code , only one code block gets run."

Christopher De Lette
PLUS
Christopher De Lette
Courses Plus Student 7,139 Points

According to the link you posted you are wondering about comments in JavaScript. Using the // method is to comment out one single line of code, whereas the /* Comment here */ method is used to comment multiple lines of code and for me is what i use to test other parts of my code if i'm writing longer js programs.

As far as your second question a code block is nothing more than a block of code. JavaScript statements can be grouped together in code blocks, inside curly brackets {...}. For example say the following simple code has been written:

if (conditional statement) {
*your code here*
}
else {
*do something other than the first snippet of code inside my if statement*
}

There are two code blocks in this example and the purpose of code blocks is to define statements to be executed together. You can have any variation of a block of code, some longer and some many shorter. Hope this helps.

Thanks and Happy Coding! Chris