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 trialSteven Bister
12,011 PointsStuck on Code Challenge: Manipulating Numbers
Ok so I'm probably missing something really obvious here but I can't seem to get this last challenge to pass at all. Here's the challenge "Create a New Float Variable named $floatOne with a value of 1.5. Multiply $integerOne by $floatOne and display the results."
Here's my code. I can't see how it isn't working, but it keeps saying that task two is now not passing.
<?php
//Place your code below this comment
//task 1
$integerOne = 1;
$integerTwo = 2;
//task two
$integerOne += 5;
$integerTwo -- ;
echo $integerOne;
echo $integerTwo;
//task 3
$floatOne = 1.5;
$integerOne = $integerOne * $floatOne;
echo $integerOne;
?>
Any help would be appreciated :)
Steven Bister
12,011 PointsHere you go https://teamtreehouse.com/library/php-basics-2/unit-converter/manipulating-numbers
Does that help?
Maddalena Menolascina
6,668 PointsI performed the task 3 differently: $floatOne = 1.5; echo $integerOne * $floatOne; It worked for me
Jack Kuhry
3,551 PointsThanks, Angel&Yle Meno&Frog, your answer worked for me also! Thank you!
11 Answers
Aaron Coursolle
18,014 PointsCreate a new variable to assign to the formula and see if that will work.
Jason Anello
Courses Plus Student 94,610 PointsOr you could even echo out the result of the multiplication directly without assigning to another variable.
Steven Bister
12,011 PointsHmm, I tried it but instead of failing task two it just says something like "have you multiplied that correctly?"
Is this what you were getting at?
<?php
//Place your code below this comment
//task 1
$integerOne = 1;
$integerTwo = 2;
//task two
$integerOne += 5;
$integerTwo -- ;
echo $integerOne;
echo $integerTwo;
//task 3
$floatOne = 1.5;
$product = $integerOne * $floatOne;
echo $product;
?>
I've added a link to the challenge above if that helps... I really don't get it because it is printing out the value... :/
Thanks!
Jason Anello
Courses Plus Student 94,610 PointsHi Steven,
There was 2 issues.
What Aaron mentioned, you don't want to change the value of $integerOne by reassigning it the result of the multiplication.
The second thing was that it never asks you to echo out the 2 integers. This is throwing off the final output. It should be 9 only but in your case it's 619
Steven Bister
12,011 PointsHi Jason,
Thanks that did it! Turns out echoing the other two variables was indeed causing the problem. Thanks for your help with this - and you Aaron :) I knew it'd be something obvious!
Aaron Coursolle
18,014 PointsThanks. You'll need to follow Jason's advice on a future challenge, so it's good that he stated it here.
Wilton cruz-ramirez
10,159 Points<?php
//Place your code below this comment
//task 1
$integerOne = 1;
$integerTwo = 2;
//task two
$integerOne += 5;
$integerTwo -=1 ;
//task 3
$floatOne = 1.5;
echo ( $integerOne * $floatOne );
?>
osvaldo gonzalez
2,167 Points$floatOne = 1.5; var_dump($integerOne * $floatOne); I keep this :Are you sure you multiplied correctly?
osvaldo gonzalez
2,167 Pointsif I post this the result is int(6) int(1) float(9) and I think this is the answer but I need help from you guys.
Jason Anello
Courses Plus Student 94,610 PointsHi osvaldo,
You need to echo the result instead of a var_dump. Also, make sure you're not outputting the 2 integers from the previous task.
The final output should be 9
only.
Benjamin Blois
4,530 PointsJason's advice helped me. The challenges tell you to "add to the previous code" so I was hesitant to delete the var_dumps I had put in during the last challenge.
vinayak sapkal
9,802 Points$floatOne = 1.5; echo ( $intergerOne * $floatOne );
Victoria Loisi
7,070 PointsMaybe the issue has anything to do with the space between the variable name and the -- operators?
Instead of $integerTwo -- ;
I would try $integerTwo-- ;
christopher abjornson
2,613 Points<?php
//Place your code below this comment $integerOne = 1; $integerTwo = 2;
$integerOne += 5; $integerTwo -- ;
var_dump($integerOne) ; var_dump($integerTwo) ;
$floatOne = 1.5; echo $integerOne * $floatOne ;
?>
What am i missing?
Jason Anello
Courses Plus Student 94,610 PointsTry taking out the var_dump for $integerOne and $integerTwo. It's making the final output incorrect.
Gregori Benji Ootes Gonzalez
969 PointsI have this:
<?php
//Place your code below this comment $integerOne = 1; $integerTwo = 2; $floatOne = 1.5;
echo "Result: " $integerOne * $floatOne;
?>
This supposed to work right?
Jason Anello
Courses Plus Student 94,610 PointsYou don't have the code that is changing the values of $integerOne and $integerTwo
Also, don't echo "Result: " only the multiplication.
The challenge doesn't request that and it's usually looking for an exact match on output.
So if it's looking for an output of 9
and your output is Result: 9
you probably won't pass because it doesn't match exactly.
Jonathon Schloss
3,409 PointsComment out your task 1 & 2 echo statements and it will pass!
Jayson Santos
Courses Plus Student 584 Pointsthose does not even have the correct answer, Please help coz Im still stucked.
Thanks
Mehedi Hasan
823 PointsThis is the right answer =>
//task one $integerOne = 1; $integerTwo = 2; $floatOne = 1.5;
//task two $integerOne = $integerOne + 5; $integerTwo = $integerTwo - 1;
//task three $multiply = $integerOne * $floatOne; echo $multiply
Steven Parker
231,236 PointsSteven Parker
231,236 PointsA link to the challenge would be very helpful.