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 The Solution

Wilson Parks
Wilson Parks
3,813 Points

For the doWhileLoops solution demonstration, Is there a reason that there were no semi-colons in the solutions?...

I noticed that when the instructor showed the solutions, there were no semi-colons used to break up statements in the doWhileLoops Solutions.

Also, I personally never got the doWhileLoops.js to output correctly in the console. It just either gave me errors or just outputted 0.

for example:

// 1. Write a while loop to build a string of numbers from 0 to 4, // separated by spaces, and store the string in the variable text. print('1st Loop:'); text = '';

// Write 1st loop here: i = 0; do { text += i += ' '; i += 1; } while (i <= 4);

print(text); // Should print 0 1 2 3 4...

It outputted 0 in the console for me.

2 Answers

Steven Parker
Steven Parker
229,785 Points

Semicolons are optional at the end of a line, but it is considered a "best practice" to include them. The code shown is valid, but it could have been better. :see_no_evil:

And you have a syntax error in this statement:

  text += i += ' ';  // <-- there is an extra = on this line
  text += i + ' ';   // fixed

Semicolons are considered 'best practice' and TeamTreeHouse could have included them :) I've noticed it as well.