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 trialRyan Lucas
6,946 PointsHelp with previous for looping objective.
I get the error " Make sure you end with 100 "
this is my code
<p>
for ($i = 0; $i < count($facts); $i++) {
echo $facts[$i] . "\n";
}
</p>
can anybody help please? ps. the <p> tags aren't in my code.
3 Answers
Ella Ruokokoski
20,881 Pointsin the first task you are simply tasked to create a for loop to loop from 1-100. You don't need to use the $facts array for the first task at all. Just plain numbers and then echo the $i variable.
Vincentius Ronalto
4,432 Points<? php
//the first task
for ($i = 1; $i <= 100; $i++) {
echo"$i\n";
echo"<br>";
}
?>
the first task of the challenge want us to print 1 until 100, so don't need worry about the array, just simple for-loop, for the second, if there are some value in array[$i] you must print it, you can use if statement checking with isset()... try to do it first :D
example:
your result must like these:
1
2
3 there is some value
4
5 there is some value
.
.
.
...until 100
julian Ellis
3,542 PointsI used this which works outside of the workspace but not inside it??????
for ($i = 1; $i <= 100; $i++) { echo $i; if (isset($facts)) { echo " " . $facts[$i] . "<br />\n"; } }