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 trialmoath alqutoob
2,450 Pointsi cant solve this
he code block below displays a list of two letters from the Latin alphabet using echo statements. But these two letters are NOT my favorite letters! In this code challenge, we’ll change this block of code to display my real favorite letters. We’ll also modify it to use an array so that it’s easier to add a new letter in the future. Before the first echo statement, create an array called letters. Give that letters array one element with a value of “D”.
<?php
echo "My favorite "; echo "2"; echo " letters are these: "; echo "AB"; echo ".";
?>
<?php
$letters=array("D","G","L");
echo "My favorite ";
echo count($letters);
echo " letters are these: ";
foreach($letters as $letter) {
?>
echo "AB"; }
echo ".";
?>
1 Answer
Grace Kelly
33,990 PointsHi moath, this step of the code challenge asks you to contain echo "AB"; within a foreach loop. You have the code correct however you are closing it of with "?>" before the foreach loop has finished, which means any php after that closing tag will not execute until you open it up again with "<?php". To solve this, simply remove the "?>" and it should work, like so:
<?php
foreach($letters as $letter) {
echo "AB";
}
echo ".";
?>
hope this helps!!