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

PHP

Array Keys Code Challenge quest 2

Hello, I just want to learn what I am doing wrong on the second part of the code challenge, where it asks me to include the isbn variable in parentheses.
"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."
Is the answer to use the html characters for the parentheses?

Andrew Shook
Andrew Shook
31,709 Points

Could you post the code that you are currently using?

3 Answers

Hi Andrew,

Sure: I will try to enclose it in backticks so it will show up: Here's the question: "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 attempt <li><?php echo $book . ($isbn) ?></li>

Here's the response: Bummer! I see all the book titles and the ISBNs in the browser, but the formatting is not quite right. Each list item should look like this: Book Title (978-0123456789)

It's showing up like this: Gilgamesh978-0743261690

I thought the answer had to do with displaying the parenthesis as a character and not part of the code.

Thanks!

Andrew Shook
Andrew Shook
31,709 Points

Your problem is a syntax error. The problem asks you to add the ISBN, surrounded by parentheses, after the book's title. Since you are printing out the parentheses to the screen, you need make them a string. Add quotes around the parentheses and concatenate them with the $isbn variable. your code should look something like this:

<li><?php echo $book." (".$isbn.")";?></li>

Don't forget to add the space before the first parenthesis so that the php prints out a space between the title of the book and the first parenthesis.

Aha! Thank you!