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 trialJoshua Marcoux
7,170 PointsA problem with your challenge
First off, let me say that I was able to complete the challenge. The issue I am having, however, is that the spelling in the challenge is incorrect, and this is causing errors. For the first part of the challenge, here is the code that I created:
<?php $recommendations = array("hi"); ?><html> <body> <h1>Flavor Recommendations</h1> <ul> <?php if (!empty($recommendations)) { foreach($recommendations as $flavor) { echo "<li>" . $flavor . "<li>"; } }else{ echo "There are no recommendations for you."; } ?> </ul> </body> </html>
This however, was not correct to complete the challenge. (apparently.) So I messed with it for a couple of minutes and figured out that if I removed one of the "m"s from the word "recommendations" on the line if (!empty($recommendations)) { Then it worked. So this is something that should be fixed. Hope I'm not out of line in pointing this out. Thanks!
1 Answer
Colin Bell
29,679 PointsI'm not really sure how that got it to work, but there are a few things with your answer that aren't consistent with what the challenge is asking for.
- The ul tags should be after the (!empty($recommendations)) conditional and before the foreach. That way, a list is only created if an array item exists.
- Your closing li tag is missing the backslash.
- Your else message is not wrapped in p tags.
<?php
$recommendations = array( 'Avocado Chocolate');
?>
<html>
<body>
<h1>Flavor Recommendations</h1>
<?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>";
}?>
</body>
</html>
Joshua Marcoux
7,170 PointsJoshua Marcoux
7,170 PointsYeah sorry about the crude code... that was actually my attempt to recreate my original conditions... This did get it to work, but my original was different. Thanks for the corrections.