JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Review while loops, do...while loops, and Loop Conditions

Morgan Walstrom
Morgan Walstrom
2,281 Points

What is the correct answer?

what did i do wrong?

Morgan Walstrom
Morgan Walstrom
2,281 Points

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; do { console.log('#' + 1); x += 1; } while ( x <= 15 )

4 Answers

Erik Krieg
MOD
Erik Krieg
Treehouse Moderator 41,118 Points

You are only adding 1 to x, while the question is expecting x to increase by 2.

Steven Parker
Steven Parker
116,121 Points

If you use a literal in the log statement, it will always log the same thing (in this case every line will have "#1").

Also, you may need a different increment value if you don't want all adjacent numbers. (1,2,3,4,5 ... etc.)

Morgan Walstrom
Morgan Walstrom
2,281 Points

I figured it out! But thanks for the response guys!

Simon walters
PRO
Simon walters
Pro Student 8,960 Points

Hey Guys

I am stuck on this question also, I have re-watched the videos numerous amount of times and I can't seem to get my head around this particular question, I have answered 4 out of the 5 questions correctly which allows me to move on to the next part of the course. I would still like to know why I wasn't getting this question, can someone please share with me how they approached this?

Thanks

Simon

Steven Parker
Steven Parker
116,121 Points

Since this question has already been answered, start a new one and show your code in it. If you use the "get help" button in the challenge, it should include and format your code for you.