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 trialTeslim Adeyemo
21,275 PointsI have been stuck on this code challenge. What I am doing wrong please!
I have tried several ways of solving this challenge. But now I have to reach out to the community. I can't see what I'm doing wrong in the code I pasted can somebody help out? The question is: If the array is NOT empty, the foreach loop will execute. But if it IS empty, we should display a message. Add an else block to the conditional that displays the following message in an HTML paragraph tag: 'There are no flavor recommendations for you.'
<?php
$recommendations = array();
?><html>
<body>
<h1>Flavor Recommendations</h1>
<?php if (!empty($recommendations)) { ?>
<ul>
<?php foreach($recommendations as $flavor) { ?>
<li><?php echo $flavor; ?></li>
<?php } ?>
</ul>
<?php } ?>
<?php else {
echo "<p>There are no flavor recommendations for you.</p>"; }
?>
</body>
</html>
Paolo Scamardella
24,828 PointsWhat's your issue? As far I can see, you are not iteration over your array or not getting any results because your array is empty.
1 Answer
Sean T. Unwin
28,690 PointsSo close. :)
The closing bracket is missing for the else
statement.
I also noticed 'recommendations' is spelled incorrectly.
ProTip: When a challenge asks you to have a specific phrase in the answer, copy and paste it from the challenge request. :)
Teslim Adeyemo
21,275 PointsThanks so much. Though I added it, still can't solve the problem. Is there any other thing I should do? I actually, below is the code challenge I am trying to solve: If the array is NOT empty, the foreach loop will execute. But if it IS empty, we should display a message. Add an else block to the conditional that displays the following message in an HTML paragraph tag: 'There are no flavor recommendations for you.'
Sean T. Unwin
28,690 PointsI found another error - a typo. I have adjusted my original answer.
Teslim Adeyemo
21,275 PointsThanks man for the tips and for helping out. But am still stuck I did all you said yet I keep receiving the Bummer jest. I am really a Bummer, What a challenge!
Teslim Adeyemo
21,275 PointsTeslim Adeyemo
21,275 PointsSorry, below is my code