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 trialnicholas maddren
12,793 PointsSo 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?
1 Answer
Keith Kelly
21,326 PointsThis 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 ".";
?>
nicholas maddren
12,793 Pointsnicholas maddren
12,793 PointsUPDATE: 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!