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 trialEllen Sun
1,605 PointsHow come the else statement is echoed?
I am following along in the video and have typed up this code in the workspace:
<?php
$current_user = 'Mike';
function is_mike() {
global $current_user;
if($current_user == 'Mike'){
echo 'It is Mike';
} else {
echo 'Nope, it is not Mike';
}
}
is_mike();
When I click on the 'eye' icon, I am taken to a view in my browser that echos out 'Nope, it is not Mike' when it should echo 'It is Mike'. Why is that?
Did I do something wrong in my code?
3 Answers
Ted Sumner
Courses Plus Student 17,967 PointsTry clearing your cache. People have reported strange cache issues. Also, post a snapshot to your malfunctioning workspace and we can see if we have the same problem. Do that by clicking on the camera icon in the upper right and following the steps to open the snapshot. Then paste the URL here.
Ellen Sun
1,605 PointsI think it was the cache issue. I chose to follow along on my computer instead of using the workspace. Thanks for your reply!
Kevin Korte
28,149 PointsWeird, I copied and pasted your code exactly and got the correct results. Take a look, here: https://w.trhou.se/p8jblhag3n
Nothing looks wrong with that code.
Ellen Sun
1,605 PointsHey Kevin,
Thanks for your reply. I tried the code offline on my computer and it also worked fine, so I think there was a glitch in using the Treehouse workspace, though I'm not sure what could cause it.
Steve Jones
Java Web Development Techdegree Student 78 PointsYeah, in offline it works.
Ted Sumner
Courses Plus Student 17,967 PointsTed Sumner
Courses Plus Student 17,967 Pointsedited to add
<?php
to beginning of code.