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 trialChristina Giannouli
18,202 PointsWhy isn't this correct?
On stage 4, challenge 5 of 7 on the Listing Inventory Items, Randy Hoyt asks for this:
<?php
$movie = array(
"title" => "The movie title",
"year" => 1980
);
?>
<h1><?php echo $movie["title"]; ?> (<?php echo $movie["year"]; ?>)</h1>
Before I finally figure out the correct answer - it took me one hour - I tried this piece of code:
<h1><?php echo $movie["title"] . "(" . $movie["year"] . ")"; ?></h1>
So, I am wondering what's the difference between the two answers and why isn't the second answer the correct one?
3 Answers
Jason Anello
Courses Plus Student 94,610 PointsHi Christina,
The challenge requires a space between the movie and year.
You can pass the challenge using string concatenation but you did not preserve the space between the movie and year.
This will pass:
<?php echo $movie["title"] . " (" . $movie["year"] . ")"; ?>
I put a space before the left parenthesis.
tihomirvelev
14,109 PointsI'm (still) not familiar with the challenge but...
Both codes actually output the same thing but the first code outputs one additional space.
First output: The movie title (1980)
Second output: The movie title(1980)
Maybe that's breaking the validation and there is a requirement for the output without space.
Christina Giannouli
18,202 PointsJason Anello , tihomirvelev thank you both!
So, it was that little space over there that almost drive me crazy! :P I really appreciate your quick response! I don't think I could have managed to figure it out by myself!
Unfortunately I can't mark as best any answer because both are the best.