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
Jason Blomquist
2,300 PointsLost with no hints
Right now, the text shows the wrong letters; we want it to display my real favorite letters from the array. In the next few tasks, we’ll change that. This task has two steps.
- Add the start of a foreach loop with an opening curly brace between the third and fourth echo commands. The foreach loop should load each element from the letters array, one at a time, into a working variable named letter.
- Add the closing curly brace for the foreach loop between the fourth and fifth echo commands. (Leave the letters AB in the fourth echo command for now. At the end of this step, the page should say my favorite letters are ABABAB.)
I have watched the video several times and still can't get this one right, what is the code supposed to look like? I have no idea what to try next.
8 Answers
Randy Hoyt
Treehouse Guest TeacherHey @Jason,
Where the code has this ...
echo "AB";
... you need to change it to this ...
foreach ($letters as $letter) {
echo "AB";
}
Does that help?
Yusuf Diyab
2,485 Points<?php
$letters = array("D","G","L");
echo "My favorite ";
echo count($letters);
echo " letters are these: ";
foreach ($letters as $letter) {
echo "AB";
}
echo ".";
?>
Here's the answer for it
Ryan Cates
18,344 PointsI'm working on this challenge ATM. I'm pretty sure I have everything right, but it still says I'm wrong. This is my code...
<?php $letters = array("D","G","L");
echo "My favorite "; echo count($letters); echo " letters are these: "; foreach ($letters as letter) { echo "AB"; } echo ".";
?>
Possibly BUG????
Dan Gorgone
Treehouse Guest TeacherHi Jason, can you be more specific about the project, stage, and code challenge you're working on? Adding tags to the post might help get the appropriate people to find your questions as well.
John Rugge
6,671 PointsHi Dan please check out my query at the bottom. stuck.
Alexander Sobieski
6,555 PointsThis is for Randy -- it's he BUILD A PHP APP (when he teaches about the 'foreach loop')
I forgot the context of the quiz question, so I can't be of help. sorry!
John Rugge
6,671 PointsThe code challenge says i have too many colons and wont pass dont seem to see where im going wrong here. Please help.
<?php
$letters = array("D", "G", "L"); echo "My favorite "; echo "Number of letters is: " . count($letters); echo " letters are these: "; foreach($letters as $letter) { echo "AB"; } echo ".";
?>
Randy Hoyt
Treehouse Guest TeacherTake a look at the output in the right. At this step, I believe it should say this:
My favorite 3 letters are these: AB.
If you look at the output, I suspect your output has more than that. Modify the code so that it displays exactly what you see above.
Does that help?
John Rugge
6,671 PointsThanks Randy the code below worked thanks to your suggestion <?php
$letters = array("D", "G", "L");
echo "My favorite "; echo count($letters); echo " letters are these: "; foreach($letters as $letter) { echo "AB"; } echo "."; ?>
John Rugge
6,671 PointsJohn Rugge
6,671 PointsHi Randy, please show the rest of the code i seem to be stuck here
Stu Cowley
26,287 PointsStu Cowley
26,287 Points