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

I seem to be missing something in the last challenge 2/3. What did I miss?

I am asked to add 5 to $integerOne and subtract 1 from $integerTwo.

http://prntscr.com/g72ebz <-- here is the code I wrote but the quiz says im wrong. I was able to get 6 for $integerOne and 1 for $integerTwo.

Im sure there is a more efficient way of writing this.

Thanks in advance.

index.php
<?php
//Place your code below this comment
$integerOne = 1;

$integerTwo = 2;

?>
nico dev
nico dev
20,364 Points

Doesn't want you to create another variable, just to add it to the variable itself with +=.

So instead of

<?php

StotalOne = $integerOne + addingvalue;

?>

It's asking you to:

<?php

$integerOne += addingvalue;

?>
nico dev
nico dev
20,364 Points

Ah, sorry, and echo is not needed, it's only asking you to add to the value, but not to output anything, so it might not allow it to pass.

HTH!

nico dev
nico dev
20,364 Points

Just a comment: take into account the idea behind the code challenges is to check if you've learned to do the things as taught in the respective videos.

Needless to say, there are many ways to achieve the same thing, and you'll learn about them all with practice and other resources and tips, but probably challenges will ask you to do what you learned during the video, so to make sure that you got that and to reaffirm it.

1 Answer

Robert Bennett
Robert Bennett
11,927 Points

Hi, there is a couple of ways to do this... What they want you to learn is how PHP can do math and make a new value in a variable with the same name.

$integerOne = 1; $integerTwo = 2 ;

$integerOne += 5; $integerTwo -= 1;

The last way is just to

$integerOne = 6; $integerTwo = 1;

I was reading through a book to see how they explained what to do. What I came up with is $integerOne = 1; $ingtegerOne = $integerOne +1;

but it did say the more professional way of doing things is to write it like $integerOne++; and it also said I could do as you mentioned Robert Bennett $integerOne += 5;

Thanks for the replies and help.