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 PHP Basics (Retired) PHP Conditionals & Loops Conditionals Challenge

I've tested my code under workspace and it works. How come this doesn't work under challenge session?

<?php $name = 'Mike'; if( $name =='Mike'){ echo 'Hi, I am' . $name . '!'; } ?>

index.php
<?php
$name = 'Mike';
if( $name =='Mike'){
  echo 'Hi, I am' . $name . '!';
}
?>

6 Answers

Kevin Korte
Kevin Korte
28,148 Points

Because it want the sentence Hi, I am Mike!. Your code would echo Hi, I amMike!. Do you see the error, and thus the solution? You're so close.

Even my version2 was not accepted.

http://port-80-8zf24qx83j.treehouse-app.com/test.php

<?php $name = 'Mike'; if($name == true){ //echo 'Hi, I am' .$name. '!'; $name = 'Hi, I am'.' '. $name . '!';

echo $name; } ?>

but anyway as long as i am absorbing and ending with correct results using workspace, that should be fine.

Kevin Korte
Kevin Korte
28,148 Points

You're still not quite seeing it. You're missing a space in your echo statement. It wants am Mike, however you echo amMike. Thus your results is not passing. Do you see the error, and solution now?

understood of the solution and i see 2 ways of doing it. is this correct?

  1. $name = 'Hi, I am'.' '. $name . '!';
  2. echo 'Hi, I am ' . $name . '!';

as i undestand these 2 creates a space.

Kevin Korte
Kevin Korte
28,148 Points

Sorry man, you're right, I got my eyes crossed when I looked at it. Yes, you are correct there. Because of the same reason I didn't catch your solution, option 2 would be the more human friendly way, and thus preferred way to add the space in the echo. But the computer doesn't really care either way....so good job!!

thanks Kevin. Now am learning!