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 trialgeoffrey
28,736 PointsCan't pass this exercise
I'm struggling to pass that simple exercise, I all the time have the answer that the array is empty but the message isn't displayed.
I've tried to format my code two ways and It's still not working. What am I missing ???
Here are the codes I've tried.
<?php
if(!empty($recommendations)){
echo "<ul>";
foreach($recommendations as $flavor) {
echo "<li>".$flavor."</li>";
}
echo "</ul>";
}
else
{
echo "<p>"."There are no flavor recommendations for you"."</p>";
}
?>
4 Answers
Ivan Uvarov
22,403 PointsThis code works:
<?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 } else {
echo "<p>".'There are no flavor recommendations for you.'."</p>";
}
?>
</body>
</html>
I just put together these 2 lines:
<?php } ?>
<?php else {
I did:
<?php } else {
Nicholas Olsen
Front End Web Development Techdegree Student 19,342 PointsYour first $recommandations is not spelt the same as your last $recommendations.
<?php
if(!empty($recommandations)){ // $recommendations IS NOT SPELLED CORRECTLY
echo "<ul>";
foreach($recommendations as $flavor) { // THIS ONE IS SPELLED CORRECTLY
echo "<li>".$flavor."</li>";
}
echo "</ul>";
}
else
{
echo "<p>"."There are no flavor recommendations for you"."</p>";
}
?>
geoffrey
28,736 PointsWell spotted, but in fact, I had typed it correctly inside the exercise, I've just checked again. In case I had missed something else, I've also copied and pasted what you did, and It's still not working. Would you mind to try this on your side, to see if you can pass it ? (the first step is validated, that's at the second one that I get stuck).
Thank you for your help.
EDIT here is the other way I formatted my code, but doesn't work neither.
<?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>";
}
?>
geoffrey
28,736 PointsThank you ! Normally what I did should work as well, If I'm not wrong.. at least, I've passed :)