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 Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Review while loops, do...while loops, and Loop Conditions

After several attempts still having trouble solving this do while quiz

tried to solve this quiz. Somehow I keep getting it wrong.

Finish the code in this do/while loop, so that the following lines are output to the console:

1

3

5

7

9

11

13

15

var x = 1; { console.log('#' + ); x += ; } ( x <= 15 )

1 Answer

There are three things in the code that are relevant: loop; print-variable; increment-value.

loop is do-while;

print-variable & increment-value: what Steven explained above.

So, as an example... with do-while loop, try printing...

1

2

3

4

If you can print that, then just increase the increment-value. Above its 1, and the question demands 2.

I have added exact answer, you can try first before checking that out.

.

.

.

.

.

Answer...

#1
#3
#5
#7
#9
#11
#13
#15

var x = 1;
do {
  console.log('#' + x);
  x += 2; 
} while ( x <= 15 )