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 Build a Simple PHP Application Listing Inventory Items Introducing Arrays

nicholas maddren
nicholas maddren
12,793 Points

So Confused

I am finding it really hard to understand what exactly the code challenge is asking of me:

I am on task 6 and I am clueless. It tells me the fourth echo statement is inside the foreach loop however if you look at my code:

<?php

$letters = array("D", "G", "L"); echo "My favorite "; echo "We have " . count($letters) . " letters" ; foreach ($letters as $letter) { echo $letter; } echo ".";

?>

You will notice that the fourth echo isn't and if I attempt to insert it there it will say task 5 is no longer passing. What am I missing?

nicholas maddren
nicholas maddren
12,793 Points

UPDATE: I have changed my code to this so it displays perfectly:

<?php $letters = array("D", "G", "L"); echo "My favorite "; echo count($letters); echo " letters are these: \n"; foreach($letters as $letter) { echo $letter; } echo ""; echo "."; ?>

Now it wont pass and says "You seem to have too many letters. You should only be displaying one letter inside your foreach loop."

The whole sentence wont make sense if it shows one letter haha it says three!

1 Answer

Keith Kelly
Keith Kelly
21,326 Points

This is the code that I have that passed:

<?php

$letters = array("D", "G", "L");
echo "My favorite ";
echo count($letters);
echo " letters are these: ";
foreach($letters as $letter){
  echo $letter;
}
echo ".";

?>