Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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..