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

yoav green
yoav green
8,611 Points

Say you had a conditional statement with one if clause..." did not understand the question

"Say you had a conditional statement with one if clause, two else if clauses and an else clause, each with its own code block. What is the maximum number of code blocks in that conditional statement that can run?"

2 Answers

In other words, in any conditional statement with multiple clauses only 1 code block will ever run. The question is not written that well as my first thought was the maximum number of evaluations so if "a" were 400, I thought it would run down the entire code block (4 evaluations).

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! The question is asking if you had something like this:

if (a < 100) {
   console.log("a is less than 100");
} else if (a < 200) {
   console.log("a is at least 100 and less than 200");
} else if (a < 300) {
   console.log("a is at least 200 and less than 300");
} else {
    console.log("a is at least 300");
}

But the point here is this: only one of those code blocks will run. It will not continue going down the list to the next evaluation. If I were to make a = 50, it will log out "a is less than 100". Now, clearly, 50 is also less than 200, but that evaluation never occurs because the first thing that evaluates to true will run and the entire if/else if/else structure will be escaped.

Hope this helps! :sparkles: