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
Fuad Adetoro
6,490 PointsStuck on Code Challenge: Array key 2/2
Question: "Next, modify the code inside the foreach loop to display the $isbn in parentheses. After the title, add a space, an opening parenthesis, the ISBN, and a closing parenthesis.".
my code which i don't know what to do with it?
<?php
$books["978-0743261690"] = "Gilgamesh";
$books["978-0060931957"] = "The Odyssey";
$books["978-0192840509"] = "Aesop's Fables";
$books["978-0520227040"] = "Mahabharta";
$books["978-0393320978"] = "Beowulf";
?><html>
<head>
<title>Five Great Books</title>
</head>
<body>
<h1>Five Great Books</h1>
<ul>
<?php foreach($books as $isbn => $book) { ?>
<li><?php echo $book; ?></li>
<?php } ?>
</ul>
</body>
</html>
it's very confusing for me i hope someone can help me :)
John Hebron
23,993 PointsYikes, messed up my echo there. Probably want to use:
echo "$book \"$isbn\""; // wrap the whole line in double quotes to render variables then place the $isbn in escaped double quotes;
Fuad Adetoro
6,490 Pointsthanks now i get it!
2 Answers
Randy Hoyt
Treehouse Guest TeacherAt the end of Step 1, the output looked like this:
Gilgamesh
The Odyssey
Aesop's Fables
Mahabharta
Beowulf
In Step 2, you need to change the code so that the output looks like this:
Gilgamesh (978-0743261690)
The Odyssey (978-0060931957)
Aesop's Fables (978-0192840509)
Mahabharta (978-0520227040)
Beowulf (978-0393320978)
Does that help?
Fuad Adetoro
6,490 Pointsthat helped a lot thanks Randy.
Makis Papadopoulos
4,679 PointsI stuck with this error: Bummer! The HTML for this page is not quite right: <html><head><title>Five Great Books </title></head><body><h1>Five Great Books</h1><ul><li>Gilgamesh (978-0743261690)</li><li>The Odyssey (978-0060931957)</li><li>Aesop's Fables (978-0192840509)</li><li>Mahabharta (978-0520227040)</li><li>Beowulf (978-0393320978)</li></ul></body></html>
My code:
<?php foreach($books as $isbn => $book) { ?>
<li><?php echo $book . " " . "($isbn)" ; ?></li>
<?php } ?>
John Hebron
23,993 PointsJohn Hebron
23,993 PointsIt seems as though you just need to print out the ISBN in quotes after the book title.