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 trialSarah F
3,052 Pointstask 2 no longer passes but code runs fine. I can't figure out why.
Task 2 was to combine first name and last name to create the variable $fullname. Task 3 I am suppose to add the string 'was the creator of PHP' and a line break. When I run the code everything works but it won't let me complete the challenge because task 2 no longer passes. I don't understand how to pass task two while running task 3.
<?php
//Place your code below this comment
$firstName = 'Rasmus';
$lastName = 'Lerdorf';
$fullname = $firstName . ' ' . $lastName;
$fullname .= ' was the original creator of PHP';
$fullname .= "\n";
echo $fullname;
?>
3 Answers
Philip Gales
15,193 PointsYour code runs, but it outputs more than they wanted. I just removed the last 2 lines for you. These challenges are very basic and rarely allow for creativity.
<?php
//Place your code below this comment
$firstName = 'Rasmus';
$lastName = 'Lerdorf';
$fullname = $firstName . ' ' . $lastName;
echo $fullname;
?>
Jennifer Nordell
Treehouse TeacherHi Sarah! The reason the previous task is no longer passing is because your code no longer satisfies those requirements. The previous step wants the firstName and the lastName to comprise the value of $fullName. But when you use the .=
to append the rest of the string there, you are overwriting what is assigned in that variable. $fullName no longer contains just his first and last name, but that entire string.
What if I changed the instructions to read: "Without changing the value of $fullname ..."?
I think you're overthinking this. Try something a little more direct like this:
<?php
var $x = 389087283;
echo "Your order number is $x";
?>
Give it another shot with these hints in mind, but let me know if you're still stuck!
Sarah F
3,052 PointsThank You!