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 trialephraim Mapuranga
2,221 PointsIn the code below, we have a simple array of contact names. We want to use the $contacts array to fill in the hardcoded
how do I answer this question
<?php
//edit this array
// echo "<li>" . $contacts[0]['name'], " : " . $contacts[0]['email'] . "</li>";
echo "<li>" . $contacts[0]['name'] . " : " . $contacts[0]['email'] . "</li>\n";
$contacts = array('Alena Holligan', 'Dave McFarland', 'Treasure Porth', 'Andrew Chalkley');
$contacts = array(
array('name' => 'Alena Holligan', 'email' => 'alena.holligan@teamtreehouse.com'),
array('name' => 'Dave McFarland', 'email' => 'dave.mcfarland@teamtreehouse.com'),
array('name' => 'Treasure Porth', 'email' => 'treasure.porth@teamtreehouse.com'),
array('name' => 'Andrew Chalkley', 'email' => 'andrew.chalkley@teamtreehouse.com'),
);
echo "<ul>\n";
//$contacts[0] will return 'Alena Holligan' in our simple array of names.
echo "<li>" . $contacts[0]['name'], " : " . $contacts[0]['email'] . "</li>";
echo "<li>" . $contacts[1]['name']. " : " . $contacts[1]['email'] . "</li>";
echo "<li>" . $contacts[2]['name']. " : " . $contacts[2]['email'] . "</li>";
echo "<li>" . $contacts[3]['name']. " : " . $contacts[3]['email'] . "<li>\n";
echo "</ul>\n";
?>
2 Answers
Jason Anello
Courses Plus Student 94,610 PointsHi ephraim,
You mostly have the correct code that you need to pass task 3 but there's a few problems.
You're echoing an extra li
near the top which will make the final output wrong.
The other issue is that you modified the closing li tags.
They should look like this: </li>\n
You're missing the line return on the first 3 closing li tags and you're missing the forward slash on the last one.
ephraim Mapuranga
2,221 Pointsthanx so much for the response I have made the corrections like pointed out but still I'm failing to get through. now my programme looks like
<?php
//edit this array
// ececho "<li>"ho "<li>" . $contacts[0]['name'], " : " . $contacts[0]['email'] . "</li>";
$contacts = array('Alena Holligan', 'Dave McFarland', 'Treasure Porth', 'Andrew Chalkley');
$contacts = array(
array('name' => 'Alena Holligan', 'email' => 'alena.holligan@teamtreehouse.com'),
array('name' => 'Dave McFarland', 'email' => 'dave.mcfarland@teamtreehouse.com'),
array('name' => 'Treasure Porth', 'email' => 'treasure.porth@teamtreehouse.com'),
array('name' => 'Andrew Chalkley', 'email' => 'andrew.chalkley@teamtreehouse.com'),
);
echo "<li>\n";
//$contacts[0] will return 'Alena Holligan' in our simple array of names.
//echo"<li>" . $contacts[0]['name'] . " : " . $contacts[0]['email'] . "</li>\n";
echo "<li>" . $contacts[0]['name'], " : " . $contacts[0]['email'] . "</li>\n";
echo "<li>" . $contacts[1]['name']. " : " . $contacts[1]['email'] . "</li>\n";
echo "<li>" . $contacts[2]['name']. " : " . $contacts[2]['email'] . "</li>\n";
echo "<li>" . $contacts[3]['name']. " : " . $contacts[3]['email'] . "</li>\n";
echo "</li>\n";
?>
Jason Anello
Courses Plus Student 94,610 PointsYou made an additional change that you didn't have before. The original code had opening and closing ul tags for the list items. You changed them to li tags which would make the final output wrong.
So where you have echo "<li>\n";
it should be changed to echo "<ul>\n";
and the same thing for the very bottom closing one.