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 trialAlana Weaver
656 PointsWhy is my PHP code incorrect?
I followed the directions of task but I'm getting an error that Task One is no longer passing when I add 5 to $integerOne and subtract 1 from $integerTwo.
<?php
//Place your code below this comment
$integerOne =1;
$integerTwo =2;
$floatOne =1.5
$integerOne =1+5;
$integerTwo =2-1;
?>
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, Alana! The reason it's saying that Task 1 is no longer passing is because you've introduced a syntax error and your code can no longer be compiled. You forgot a semicolon at $floatOne =1.5
.
In step 2, you are asked to add five to integer one and subtract 1 from integer two. While it passes the challenge with the way you are doing it, it defeats the purpose of using variables if you're hardcoding it. The idea is that we want the value of $integerOne
to be increased by 5 no matter what it was set to originally. Your code will always set $integerOne
to equal 6. But what if it had been 10 to start with?
We could write something like this:
$integerOne += 5;
This will take whatever the value of $integerOne is, add 5 to it, and then assign the result back into $integerOne.
Hope this helps!
Alana Weaver
656 PointsYes I added the missing semicolon and passed Step 2
Alana Weaver
656 PointsAlana Weaver
656 PointsOk I kept $integerOne value the same without changing its value and add 5 like this $integerOne = $integerOne + 5;
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherThat should be fine. And if you fix the missing semicolon, it should pass Step 2.