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 trialli guopeng
8,873 Pointscode challenge
Write a while loop to display the numbers 1 through 9, all on one line with no spaces: 123456789. (You will need a counter variable to keep track of the number of times the while loop has executed; name that variable $i.) Bummer! The output should contain only numbers 1 through 9, without any spaces or punctuation.
<?php
$i= 0;
while ( $i < 9 )
{
$i+=1;
echo $i;
}
?>
3 Answers
Flamur Beqiri
6,908 PointsOk it seems that this is a work-space problem from TeamTreeHouse , forget my answers what i posted and know that your code is right ;)
Flamur Beqiri
6,908 Pointsif you write $i<9 it will only get the 8 not the 9, because the 9 is not <than 9 , with equal it will get also the 9 because the 9 is <= 9
Joe Cochran
18,249 PointsBut $i <= 9
will output 1-10, and the quiz is asking for 1-9. If I take their original code and run it through php, I get the output 123456789.
Also, I copied their code directly into the challenge and it passed, so I am pretty sure they hit some sort of Javascript problem with the challenge engine. Please see this screenshot:
https://www.dropbox.com/s/9p5n7w41v4yzfj6/challenge-screen.png?dl=0
Flamur Beqiri
6,908 Points$i= 0;
while ( $i <= 9 )
{
$i+=1;
echo $i;
}
?>```
this should work
William Li
Courses Plus Student 26,868 PointsHi, Flamur Beqiri can you please also add a little explanation on why your code solves the problem where questioner's code failed? That'd help others understand the problem better.
Joe Cochran
18,249 PointsJoe Cochran
18,249 PointsTry refreshing the page and entering that again. When I input your code it correctly completes the challenge.