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 trialOğulcan Girginc
24,848 PointsStuck in the PHP Development Code Challenge: Introducing Arrays
Hi, this is the challenge:
The fourth echo statement, the one inside the foreach loop, should display my favorite letters from the array INSTEAD of AB. Remove the static piece of text from that fourth echo statement, changing it instead to display the value for the array element under consideration inside the foreach loop.
However, I couldn't understand what does it ask for in the second sentence. It is keep saying: Bummer! You seem to have too many letters. You should only be displaying one letter inside your foreach loop.
Can someone help please?
Thanks! :)
<?php
$letters = array("D", "G", "L");
?>
<pre><?php
echo "My favorite ";
echo count($letters);
echo " letters are these:\n";
foreach($letters as $letter) {
echo $letter . "/n";
}
echo "A B";
echo ".";
?>
3 Answers
Stephen Van Delinder
21,457 PointsThe output for your code is basically correct, I imagine the problem stems from the use of the <pre> tag. Occasionally formatting issues will cause "Bummers" in treehouse. I cleaned up your code above and got it to pass successfully.
A great resource to test and debug code for these challenges is: http://sandbox.onlinephpfunctions.com/ This sandbox will allow you to see if your code functions correctly, and if not you can find the line number and error type.
<?php
$letters = array("D", "G", "L");
echo "My favorite ";
echo count($letters);
echo " letters are these: ";
foreach($letters as $letter) {
echo $letter;
}
echo ".";
?>
Hope this helps!
Clayton Perszyk
Treehouse Moderator 48,850 PointsTry removing echo "A B";. If that doesn't work you might need to remove the new-line characters.
Oğulcan Girginc
24,848 PointsI have ended up like this:
<?php
$letters = array("D", "G", "L");
?>
<pre><?php
echo "My favorite ";
echo count($letters);
echo " letters are these:";
foreach($letters as $letter) {
echo $letter;
}
echo ".";
?>
But it keeps saying: "Bummer! You seem to have too many letters. You should only be displaying one letter inside your foreach loop."
Anymore ideas?
Oğulcan Girginc
24,848 PointsOğulcan Girginc
24,848 PointsThank you very much Stephen!
Jan Plas
2,587 PointsJan Plas
2,587 PointsThanks!