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

Alex Lang
Alex Lang
1,110 Points

I don't know how to get the right answer here...

var x = 1; Do { console.log('#' + x); x += 14; //Why is 14 wrong? What do I do here?// } while ( x <= 15 )

2 Answers

According to the quiz here is what is displayed in the console

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

The initial value of x is 1 so that is logged the first time through. The next value logged is 3. 1 + 2 = 3. and so on.

If it were x += 1 then all numbers would be logged.

Alex Lang
Alex Lang
1,110 Points

Gotcha, Thanks for the help

You are logging ever other number so each time you loop you would increment by 2.

Alex Lang
Alex Lang
1,110 Points

How do I know every other number i being logged? instead of x += 1;?