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 trialSimon walters
Courses Plus Student 8,962 PointsFinish the code in this do/while loop, so that the following lines are output to the console:
Hi guys
Can someone please advise me on how to approach this? I have watched the videos leading up to this question numerous times and I am still struggling to understand, I have made several attempts at it but can't complete it. I have answered 4 of the 5 questions correctly which enables me to move forward with the course, but I would still like to understand.
Thanks
Simon
1
3
5
7
9
11
13
15
var x = 1;
do {
console.log('#' + ? );
x += ? ;
} while ( x <= 15 )
2 Answers
Matthew Long
28,407 PointsYou want to log x
to the console and increment x
by 2
each time in order to get that 1, 3, 5, 7...
pattern.
var x = 1;
do {
console.log('#' + x);
x += 2;
} while ( x <= 15 )
Romain Gaget
24,449 Pointsyou need to increase x by 2 (1,3,5...) and console log x
var x = 1;
do {
console.log('#' + x );
x += 2 ;
} while ( x <= 15 )
Simon walters
Courses Plus Student 8,962 PointsSimon walters
Courses Plus Student 8,962 PointsOf course, now that i see it in front of me it makes perfect sense!
Thanks Matthew :)
Omar Ocampo
3,166 PointsOmar Ocampo
3,166 PointsThanks Matthew, this was the best response
Aryan Mehta
3,595 PointsAryan Mehta
3,595 PointsI understood the code but I feel lost with the mathematics behind this. When x = 1, 1+2 will be 3. But when x=2, 2+2 will be 4 which is not listed. Can you please help me understand this? Thank you