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

PHP

Katrina Hussain
Katrina Hussain
11,177 Points

Code Challenge Help: Task 7 of 7 - Build a Simple PHP Application -> Listing Inventory Items -> More Excitement With Arrays

Task: Now let's add another flavor to the ice cream store. Add a fourth element to the array with a value of "Cookie Dough" (my personal favorite). When you preview the code, notice that the count of flavors increases and the new flavor is added to the list automatically.

Code:

<?php $flavors = array("Chocolate", "Vanilla", "Cookies and Cream", "Cookie Dough");?> <p>Welcome to Ye Olde Ice Cream Shoppe. We sell <?php echo count($flavors); ?> flavors of ice cream.</p> <ul> <?php foreach($flavors as $flavor) {?> <li><?php echo $flavor; ?> <?php } ?></li> </ul>

HTML Result: Welcome to Ye Olde Ice Cream Shoppe. We sell 4 flavors of ice cream.

  • Chocolate
  • Vanilla
  • Cookies and Cream
  • Cookie Dough

I am not sure what I'm doing wrong. I've added Cookie Dough to the array. The count automatically increased and the new flavor showed up as well but I keep getting an error!

Error: Bummer! The unordered list should have exactly four items in it.

Any ideas?

I figured it out My closing brace for the foreach statement should have come after the closing list tag!

<li><?php echo $flavor; ?></li> <?php } ?> </ul>

5 Answers

Matthew Dilello
Matthew Dilello
6,203 Points

Hint - Check you have have placed the close of the foreach.

Matthew Dilello
Matthew Dilello
6,203 Points

Oops, I see you already figured it out.

Katrina Hussain
Katrina Hussain
11,177 Points

Thanks Matthew. It's always some little detail that's missed after staring at the code for a while, wondering why its wrong, even though it produces the right output! =)

Im having a mental breakdown trying to get past this. I've copied the code and it still doesn't pass

<?php $flavors = array ("Chocolate", "Vanilla", "Caramel", "Cookie Dough"); ?>

<p>Welcome to Ye Olde Ice Cream Shoppe. We sell <?php echo count($flavors); ?>flavors of ice cream.</p> <ul> <li><?php foreach ($flavors as $flavor) { ?> <?php echo $flavor; ?></li> <?php } ?> </ul>

<?php

    $flavors = array("Chocolate", "Vanilla", "Cheese", "Cookie Dough");

?>
<p>Welcome to Ye Olde Ice Cream Shoppe. We sell <?php echo count($flavors); ?> flavors of ice cream.</p>
<ul><?php foreach ($flavors as $flavor) { ?>
    <li><?php echo $flavor; ?></li>
  <?php } ?>
</ul>

Hope it will help you..