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
Jason Blomquist
2,300 PointsMore excitement with arrays code challenge question #5
Right now, the unordered list does not show the flavors from our array. In the next few tasks, we'll change that. This task has two steps. (1) Add the start of a foreach loop with an opening curly brace after the opening <ul> tag but before the first opening <li> tag. The foreach loop should load each element from the flavors array, one at a time, into another variable named flavor. (2) Add the closing curly brace for the foreach loop after the final closing </li> but before the closing </ul>.
My code looks like this:
<?php
$flavors = array("Chocolate" , "Vanilla" , "Oreo");
?>
<p>Welcome to Ye Olde Ice Cream Shoppe. We sell <?php echo "3"; ?> flavors of ice cream.</p>
<ul>
{
<?php foreach($flavors as $flavor) { ?>
<li><?php echo $flavor; ?></li>
; ?></li>
php } ?>
</ul>
I cant tell whats wrong with it any sugestions on how to figure it out?
13 Answers
Alexander Sobieski
6,555 Points@jason
I don't know if the forum software mucked up the code, or if this is exactly what you typed into the code challenge... but it's all kinds of not correct syntax going on.
best bet: re-watch the video and take the code challenge over.
-- but that aside, I don't see anything telling the php to give you the ul and li tags.
Randy Hoyt
Treehouse Guest TeacherIt should look like this
<?php
$flavors = array("Chocolate" , "Vanilla" , "Oreo");
?>
<p>Welcome to Ye Olde Ice Cream Shoppe. We sell <?php echo count($flavors); ?> flavors of ice cream.</p>
<ul>
<?php foreach($flavors as $flavor) { ?>
<li><?php echo $flavor; ?></li>
<?php } ?>
</ul>
Alexander Sobieski
6,555 Points@jason - for the record, the code in your post looks MUCH better now... maybe it was a browser thing or the forum software.
Jason Blomquist
2,300 PointsHi Randy,
My code now looks like this:
<?php
$flavors = array("Chocolate" , "Vanilla" , "Oreo");
?> <p>Welcome to Ye Olde Ice Cream Shoppe. We sell <?php echo count($flavors) ?> flavors of ice cream.</p> <ul
<?php foreach($flavors as $flavor) { ?> <li><?php echo $flavor; ?></li> ; ?></li> <? php } ?>
</ul>
5 still says recheck your work....why is this if I changed my code to match yours?
Please help.
Randy Hoyt
Treehouse Guest Teacher(Hey @Jason, If you use four spaces at the beginning of a line of code here in the forum, it will get formatted and displayed properly.)
Your code does not look the same as mine. My code had these two lines:
<li><?php echo $flavor; ?></li>
<? php } ?>
Your code has an extra line in between them:
<li><?php echo $flavor; ?></li>
; ?></li>
<? php } ?>
That extra line is causing the problem. You have a closing php tag ?> that doesn't have an opening php tag <?php to match it, and it throws an error.
Does that help?
Alexander Sobieski
6,555 Points@jason
If your code matches @randy's code, it might be the code challenge tool itself.
I know that I've had correct answers flagged as "incorrect" -- only to redo the code challenge and have the identical answer load as correct. -annoying when you know the answer is correct... painful if you're learning something new and aren't 100% confident enough to say for sure.
[also... your code looks jacked again. -- I think it's the way we enter code into the textarea. You have to hit "spacebar" x4 to get it to format correctly. I have noticed that when I copy/paste, sometimes part of it shows as code, and part can get lost. - hope that helps]
Alexander Sobieski
6,555 Points(lol... same time!)
Jason Blomquist
2,300 PointsThat stuck out like a sore thumb now that you point it out, my bad. I am still getting an error tho. My code now looks like this?
<?php
$flavors = array("Chocolate" , "Vanilla" , "Oreo");
?> <p>Welcome to Ye Olde Ice Cream Shoppe. We sell <?php echo count($flavors) ?> flavors of ice cream.</p> <ul
<?php foreach($flavors as $flavor) { ?> <li><?php echo $flavor; ?></li>
<? php } ?>
</ul>
I'm still pretty new at this as you can see.
Randy Hoyt
Treehouse Guest TeacherCould you add four spaces at the beginning of each line of code? That way instead of looking like this ...
$spaces = 0;
... it would look like this ...
$spaces = 4;
It looks like you have a line of HTML with this:
<ul
That should look like this:
<ul>
Does that help?
Jason Blomquist
2,300 PointsI'm just going to skip the rest of this one I guess because nothing I change gets me a correct answer to this one. I'm not following what you mean by the 4 spaces. Did you want me to hit the spacebar 4 times at the begining of each line of code? Also can i earn the badge for this stage if I skip this challenge ?
Randy Hoyt
Treehouse Guest TeacherSorry you are having trouble!
- Yes, I want you to hit the spacebar four times at the beginning of a line of code to trigger the formatting.
- No, you cannot earn the badge without completing the code challenge.
Amie Parker
2,759 PointsJust letting you know that I also had problems getting this code challenge to work, maybe it could be explained differently or split up?
Cecily Madanes
Courses Plus Student 3,384 PointsThis question has very confusing wording. Correct code flags it as incorrect.
Randy Hoyt
Treehouse Guest TeacherCecily Madanes Could you paste the code here so I can see what's causing the problem?