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
Tom DuScheid
4,014 PointsAccounting for Empty Results Challenge
Stuck here. Where is the $flavors array that they are talking about?
Let's make sure that foreach loop executes correctly if the $flavors array is NOT empty. Add one element to the $flavors array with a value of 'Avocado Chocolate'.
//My Attempt on this challenge
$recommendations = array();
?><html> <body>
<h1>Flavor Recommendations</h1>
<?php
if ($recommendations != "") {
if (!empty($recommendations)) {
echo '<ul class="recommendations">';
foreach ($flavors as $flavor) {
}
echo '</ul>';
} else {
echo '<p>There are no flavor recommendations for you.</p>';
}
}
?>
</body> </html>
3 Answers
Randy Hoyt
Treehouse Guest TeacherTwo things:
(1) You don't need both of these checks:
if ($recommendations != "") {
if (!empty($recommendations)) {
The second check alone should be sufficient:
if (!empty($recommendations)) {
(2) There is supposed to be code inside the foreach loop that displays the flavor. Did you remove that?
foreach ($flavors as $flavor) {
}
Does that help?
kljnnkl gvhhgv
3,175 PointsWhat stage is that challenge in?
Saad Khan Malik
25,199 Pointsstage 5
Saad Khan Malik
25,199 Pointsthis should help....
<?php foreach($recommendations as $flavor) { ?>
<?php if (!empty($recommendations)) {?>
<?php echo "<ul>" ?>
<li><?php echo $flavor; ?></li>
<?php echo "</ul>" ?>
<?php } }; ?>
Kari Jones
6,217 PointsKari Jones
6,217 PointsHi, I am also having trouble with this code challenge. It shows a white screen with Flavor Recommendations in the preview, and the message is Bummer! The unordered list tags appear even when the array is empty. Place those tags inside a conditional that uses the empty function. Here is my code:
Can anyone help?
Dominik Seliner
511 PointsDominik Seliner
511 PointsHi Kari
You create two ul tags which is one too many Delete the echo '<ul>'; line above the if clause.