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

edgar robledo
edgar robledo
6,067 Points

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

i did not get the question can you please help. Finish the code in this do/while loop, so that the following lines are output to the console:

Justin Otero
Justin Otero
4,959 Points

[Moderator redacted]

Steven Parker
Steven Parker
231,275 Points

The answer given by Justin above is for a different question, plus explicit answers without any explanation are strongly discouraged by Treehouse.
Update: ...and apparently subject to redaction!

5 Answers

Steven Parker
Steven Parker
231,275 Points

The question shows you a bit of code that is intended to produce the output shown. Your task is to fill in the 4 blanks to complete the code.

Hints:

  • each blank should be filled in with a single word or number
  • no symbols or punctuation are needed in any blanks
  • the question itself indicates this code uses a "do/while loop", check first for those keywords

This doesn't help man lol

Steven Parker
Steven Parker
231,275 Points

It apparently did the trick for edgar! But it looks like someone posted another spoiler here, perhaps you saw it before it was redacted by a moderator.

Sorry man. Wasn't trying to make it seem offensive. That's why I put lol. I am saying maybe some pseudocode or something may be a better way to get peoples hamsters spinning

Steven Parker
Steven Parker
231,275 Points

No offense taken, and I do sometimes use pseudocode in hints. This question wasn't very specific so I was just guessing at a few things that might help. I still have to wonder about the downvotes, though.

Haha why don't you just downvote me?? It's just a rating!

Steven Parker
Steven Parker
231,275 Points

You can't vote on comments, only answers. :wink:

Try the following answer -

var x = 1;
   do {
     console.log('#' + x );
     x += 2;
} while ( x <= 15)
Steven Parker
Steven Parker
231,275 Points

:warning: Explicit answers without any explanation are strongly discouraged by Treehouse (and may be subject to redaction by staff or moderators, as was done with Justin's spoiler above).

Bartosz Kowalczyk
Bartosz Kowalczyk
4,103 Points

Your x is a number next to #, it looks like that "#x". In first run of the loop console will give you #1 because you start with var x = 1. A simple mathematical sequence has been used in the task (x + 2) therefore you need to x += 2; each time until it reaches 15.

thank you, it works

I don't understand how to do this problem. I know where there DO and the WHILE words go, but I don't know what numbers go in the remaining two spaces. I have tried: 1, 2 and 1, 3 .

Steven Parker
Steven Parker
231,275 Points

Another way to approach this is to think about (perhaps even write down) how you would write a "do...while" loop to produce the output shown. Then compare your program to the one with the blanks to determine what goes in each blank.

okay boomer Steven

Steven Parker
Steven Parker
231,275 Points

It's nice to know that answers from years ago are still being read, but I don't understand this comment. Can you explain?

Ashton Little
Ashton Little
7,352 Points

I was doing this wrong, lol.... I was doing

i += 1;

Didn't read the console output (shakes head)