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
Arvid Keskitalo
23,406 Pointsphp challenge 2 of 3
What am I doing wrong here? I only get the answer: Try again!
<?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 { ?> <p> <?php echo 'There are no flavor recommendations for you.'; ?> </p> <?php } ?>
</body> </html>
10 Answers
Gloria Dwomoh
13,116 PointsYou didn't close the if brace from the if - else properly. Here
<?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 { ?>
<p>There are no flavor recommendations for you.</p>
<?php } ?>
</body>
</html>
dorzki
4,312 Pointswhat's needs to be done? which challenge is this?
Arvid Keskitalo
23,406 PointsIf 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.'
dorzki
4,312 Pointsplease put the code here but use the code markup so i can read the code better...
Gloria Dwomoh
13,116 PointsHi Arvid, I will suggest some changes for you to do...first you have extra <?php} ?> written here...
<?php } ?> <?php } ?> <?php else { ?>
Also, it asks you to create a paragraph so you have to use HTML paragraph tags
<p></p>
and not echo. These are few suggestions. I can't really see your code well. It needs to be markdown like the other ones.
dorzki
4,312 Pointshe doesn't have an extra { one is for the loop and one for the if
Gloria Dwomoh
13,116 PointsNo he has actually written it wrong. Thanks for bring it to my attention XD because I forgot to change that part, it suppose to be written like this
<?php } else { ?>
so...overall..
<?php } ?> <?php } else { ?>
dorzki
4,312 Pointsyou are correct, but maybe he doesn't know... :P
Arvid Keskitalo
23,406 Points<?php if(!empty($recommendations)) { ?> <?php foreach($recommendations as $flavor) { ?> <?php echo $flavor; ?> <?php } ?> <?php } ?> <?php else { ?> <?php echo 'There are no flavor recommendations for you.'; ?> <?php } ?>`
Markdown starts and ends with ```?
Gloria Dwomoh
13,116 PointsWrite ``` followed by php. Click enter, paste your code. Click enter again and type 3 backticks.
Arvid Keskitalo
23,406 Points<?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>";
<?php } ?>
</body>
</html>
dorzki
4,312 Points<?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{ ?>
<p>There are no flavor recommendations for you.</p>
<?php } ?>
</body>
</html>```
dorzki
4,312 Pointsuse this...
Arvid Keskitalo
23,406 PointsOK, I got it curly braces the wrong way. Thank you Gloria!
Gloria Dwomoh
13,116 PointsYep. You are welcome :)