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 trialCarla Thomas
Front End Web Development Techdegree Student 16,039 PointsMingling PHP and HTML
I am definitely being challenged. Here's the code for the challenge:
<?php
$movie = array();
$movie["title"] = ("The Empire Strikes Back");
$movie["year"] = ("1980");
?>
<h1><?php echo $movie["title"]; ?> (1985)</h1>
Here are the instructions for the challenge:
Right now, the <h1> element has the year of the original movie (1985) as a static piece of text. Replace that with a PHP command that INSTEAD displays the year of the new movie (1980) from the array. (Be sure to leave the parentheses intact.)
Here's my answer:
<h1><?php echo $movie["title"]; ?>
( <?php echo $movie["year"]; ?> ) </h1>
Here's the error I am getting. Thanks in advance for your help.
The year of the second movie is not displayed in the <h1>.
8 Answers
Chris Southam
1,823 PointsI'm guessing you've got some additional spaces in your H1 tag (there is another post about this). I've done the course now and I can't see where it would be erroring for you.
<h1><?php echo $movie["title"]; ?> (<?php echo $movie["year"]; ?>)</h1>
Carla Thomas
Front End Web Development Techdegree Student 16,039 PointsThanks again, Chris.....there were extra spaces in my on both sides of the parenthesis.
Gregory Serfaty
37,140 Pointsi do this and it is work
<?php
$movie = array();
$movie['title'] = "The Empire Strikes Back";
$movie['year'] = 1980;
?>
<h1><?php echo $movie['title'];?> (<?php echo $movie['year'];?>)</h1>
Carla Thomas
Front End Web Development Techdegree Student 16,039 PointsThat is also my answer.....except the PHP must be maintained within the <h1> tags, which mine also does....do you know of another way to arrive at the answer?
Carla Thomas
Front End Web Development Techdegree Student 16,039 PointsThanks Gregory. The problem turned out to be that I had extra spaces on the insides of the parenthesis ()....thank you so much for your help! :)
Chris Southam
1,823 PointsWell they are the right answers when it comes to PHP but not related to what you've previously written and what Treehouse needs for the answer. I'm just going through the course myself to find the answer for you.
Gregory Serfaty
37,140 Pointsfor your array you don't need to do this ```$movie = array(); $movie["title"] = ("The Empire Strikes Back"); $movie["year"] = ("1980");
but try this
```$movie["title"] = "The Empire Strikes Back";
$movie["year"] = "1980";
Carla Thomas
Front End Web Development Techdegree Student 16,039 PointsHi Gregory,
That's the previous part of the challenge (and that was correct).
I need to change (1985) to say (1980).
Gregory Serfaty
37,140 Pointsthe error's message is the year is not in the h1 so just change the date in your array
Carla Thomas
Front End Web Development Techdegree Student 16,039 PointsThat's what my coding does above while maintaining the parenthesis () as the instructions state. Please write the code so I can better understand your correction. By the way, thanks for your help.
Gregory Serfaty
37,140 Pointsplease try to delete the () in the array and put all the sentence in one ligne
Carla Thomas
Front End Web Development Techdegree Student 16,039 PointsWhen I removed the brackets from the array, I received an error stating that the previous challenge (Task 3) is no longer passing.....the challenge wants me to continue from the previous task.
Very frustrating.
Gregory Serfaty
37,140 Pointsnormal you don't want to delete the brackets but the parenthesis and put on 1 ligne
<?php echo $movie['title'];?> (<?php echo $movie['year'];?>)
Carla Thomas
Front End Web Development Techdegree Student 16,039 PointsUnfortunately, none of the above were the correct answer. Has anyone clicked on the link located in my original post and successfully passed (Task #4) of the challenge?
Gregory Serfaty
37,140 Pointsi do and passed with success the answer 4 and my answer was just above
<?php $movie = array(); $movie['title'] = "The Empire Strikes Back"; $movie['year'] = 1980; ?>
<?php echo $movie['title'];?> (<?php echo $movie['year'];?>)
Chris Southam
1,823 PointsChris Southam
1,823 PointsTake the brackets out from each side of both variables (title & movie)
and then replace your H1 with
<h1><?php echo $movie["title"]; ?> (<?php echo $movie["year"]; ?>)</h1>