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 trialAndrew G
7,541 PointsHi there, I think there may be a bug in the PHP basics challenge. I get an error when adding $firstName = 'Rasmus ';
Hi there, I think there may be a bug in this PHP basics challenge. I get an error when adding $firstName = 'Rasmus ', with the space in order to ensure that $fullName is correct. My code:
<?php
$firstName = 'Rasmus ';
$lastName = 'Lerdorf';
$fullName = $firstName . $lastName;
echo $fullName;
?>
<?php
$firstName = 'Rasmus ';
$lastName = 'Lerdorf';
?>
1 Answer
Michael Hulet
47,913 PointsThis is not a bug. The challenge specifies that $firstName
should be set to the string "Rasmus"
, not "Rasmus "
. The space at the end of the way you have it now shouldn't be there
Andrew G
7,541 PointsAndrew G
7,541 PointsThanks Mod, but it is confusing, as Alina uses that strategy for adding a space in between names in the lesson, so it's the first thing that comes to mind, and from memory she doesn't use the concatenation technique required to solve it at all in that context: .' '.
Also, I'm only a beginner at PHP, but isn't the value still Rasmus, even if the string is 'Rasmus '? The question requests that the value be set to Rasmus.
Michael Hulet
47,913 PointsMichael Hulet
47,913 PointsNo, the value is different if there's a space at the end of the string. A space is an extra character, and a string with more characters is intrinsically different from another string with fewer. The challenge doesn't ask you to worry about combining names until the 2nd step. In the first step, it just asks you to make
$firstName
be"Rasmus"
(not"Rasmus "
), and remember that each step of a challenge must pass all the tests of the previous step, so modifying variables from the previous step is not an option hereAndrew G
7,541 PointsAndrew G
7,541 PointsAwesome, thanks for clarifying. I'm really enjoying the beginner php track, and Alina's clear and precise teaching style.:)