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 trialMadison Wuckowitsch
572 PointsI cannot figure out how to add and subtract numbers in php.
my code is the following:
<?php
//Place your code below this comment $integerOne = 1; $integerTwo = 2; ?>
the code challenge is "Add 5 to $integerOne and subtract 1 from $integerTwo."
<?php
//Place your code below this comment
$integerOne = 1;
$integerTwo = 2;
?>
2 Answers
Daniel Pérez
13,402 PointsTry this:
$integerOne = 1; $integerTwo = 2;
$integerOne += 5; $integerTwo -= 1;
The "+=" operator takes the value of the variable $integerOne and adds 5. It's equal to $intergerOne = $integerOne + 5;
Ricky Johnston
27,445 PointsHey Madison!
The PHP docs for arithmetic operators are here: http://php.net/manual/en/language.operators.arithmetic.php
TL;DR version:
For example, to add 5 to $integerOne and store the result in the same variable --
$integerOne = $integerOne + 5;
or, for shorter code
$integerOne += 5;
I know this kind of thing can feel tricky when you start. Good luck!