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 Unit Converter Manipulating Numbers

Alana Weaver
Alana Weaver
656 Points

Why 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.

index.php
<?php

//Place your code below this comment
$integerOne =1;
$integerTwo =2;
$floatOne =1.5
$integerOne =1+5;
$integerTwo =2-1;


?>

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi 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! :sparkles:

Alana Weaver
Alana Weaver
656 Points

Ok I kept $integerOne value the same without changing its value and add 5 like this $integerOne = $integerOne + 5;

Alana Weaver
Alana Weaver
656 Points

Yes I added the missing semicolon and passed Step 2