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 trialEvan Osczepinski
5,189 PointsIntegrating With paypal Challenge
I am having trouble completing part 2 of a code challenge. Here's what it is:
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.
I ended up creating new arrays for the $books var and this didn't do it. I am stuck and have watched the video again and again. Help por favor !! Thank you in advance
8 Answers
Evan Osczepinski
5,189 Pointssounds bad but I'm not sure how, just copy/paste?
Calvin Nix
43,828 PointsYeah just copy and paste.
Also surround your code with 3 backticks (```) so it will be formatted correctly.
Evan Osczepinski
5,189 Points<?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 $book) { ?>
<li><?php echo $book; ?></li>
<?php } ?>
</ul>
</body>
</html>
Calvin Nix
43,828 PointsI took care of the format for you.
Evan Osczepinski
5,189 PointsGot it! still need help with the challenge though.
Calvin Nix
43,828 PointsI already formatted your code.
When you are posting a comment, right under the text area you will see the bolded text "Markdown Cheatsheet". Click this for all markdown specifications.
Evan Osczepinski
5,189 Pointsformatted the code for the challenge? If so, where?
Calvin Nix
43,828 PointsNo in your comment :)
Calvin Nix
43,828 PointsHey Evan,
The code challenge is wanting you to load the ISBN for each book. In your case the ISBN is the key value of $books
. You will need to use =>
in your foreach statement.
Evan Osczepinski
5,189 Points$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>
This is what I have after the first part of the challenge. It's the second part that gets me. I may be just not understanding the question right..
Calvin Nix
43,828 PointsHey Evan,
The code challenge was looking for a specific format of the return book title and ISBN. If the format wasn't exact then it would count your answer wrong.
This is how you create the desired format:
(SPOILER)
<li><?php echo $book; ?> (<?php echo $isbn; ?>)</li>
Evan Osczepinski
5,189 PointsThank you Calvin! Huge help. I appreciate it!
Calvin Nix
43,828 PointsNo problem Evan!
Have a nice day.
Calvin Nix
43,828 PointsCalvin Nix
43,828 PointsCan you attach the code that you are using?