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

Adding and Subtracting

$integerOne= 1; $integerTwo= 2;

var_dump ($integerOne + 5); var_dump ($integerTwo - 1);

Hi guys. I was asked to write intergerOne with a value of 1 and integerTwo with a value of 2 as shown above on the first two sentences of code above. I was then then asked to add 5 to integerOne and Subtract 1 from integerTwo. Sentence 3 and 4 above shows my code. If i review it on preview I'm getting the correct answers which are: int (6) and int(1) respectively.

However, treehouse is rejecting my code while in preview its coming out correct. I need your help guys to solve this.

Thank you

Tatenda Chiteka

index.php
<?php

//Place your code below this comment
$integerOne= 1;
$integerTwo= 2;

var_dump ($integerOne + 5);
var_dump ($integerTwo - 1); 
?>

2 Answers

Steven Snary
Steven Snary
17,540 Points

Simon has you on the right path - sometimes the hardest part is just knowing what exactly the checker is looking for so that you can present the answer in that format.

In this case you need to complete the following steps...

  1. Declare and Initialize the variables $integerOne and $integerTwo - you've done this correctly :-)

NOTE: The reason your code is not passing is that you are never updating the actual variables $integerOne and $integerTwo - you are only outputting the results of adding 5 to $integerOne and subtracting 1 to $integerTwo. The checker will be verifying the final values of $integerOne and $integerTwo.

  1. Next you must update the values of $integerOne and $integerTwo - I'd follow Simon's lead except I'd add a space and maybe a comment before updating the value of $integerOne so that it's easy to read and follow (good habit) - note you could also update the variable like this...
$integerOne = $integerOne + 5;

I would do it the way that Simon shows - but just in case you haven't learned the shorthand to update a variable then the way I show is more explicit.

NOTE: I have checked and confirmed that these code snippets will pass the checker - Good Luck and have Fun Coding!

REMINDER: Please mark the solution(s) that you agree with and the best answer to help the Treehouse Community - both those that take the time to answer and those other students that look at this thread in the future.

Steven Snary
Steven Snary
17,540 Points

One more note to add: If you are displaying a result, as this challenge will ask for in Step 3 - you can also use "echo" in place of "var_dump".

Thanks Steven. It worked out. I appreciate your help.

Simon Coates
Simon Coates
28,694 Points

it wants you to change the values contained in integerOne and integerTwo. Here's a start:

<?php

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

?>