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 trialShilpa Kothari
4,518 Pointsarray
Challenge Task 5 of 7
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. (1) 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. (2) 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 tried a lot can anyone help. I think I am not able to understand the Question.
<?php
$letters = array();
$letters[] = "D";
$letters[] = "G";
$letters[] = "L";
echo "We have " . count($letters) . " letters.";
?>
<?php foreach($letters as $letter) {?>
<? php } ?>
<? echo "My favorite"; echo 3; echo "letters are these:"; echo "AB"; echo "."; ?>
Shilpa Kothari
4,518 PointsHi Ted,
Thanks but my question is it correct or not.
Ted Sumner
Courses Plus Student 17,967 PointsI understand your question, but I have to tell you when I edit the post as a moderator. See my answer below.
1 Answer
Ted Sumner
Courses Plus Student 17,967 PointsYour foreach loop is between the first and second echo statement, not the third and fourth as directed. Plus, no the line below that you have a space between <?
and php.
Shilpa Kothari
4,518 PointsThanks I think the question are more complicated so try to over do things and the coding is simple.
Ted Sumner
Courses Plus Student 17,967 PointsJust do exactly what it tells you to do. Often error messages tell you what you did wrong. The challenges are not tricky at all.
Ted Sumner
Courses Plus Student 17,967 PointsTed Sumner
Courses Plus Student 17,967 Pointsedited to format code