Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

Steven Bister
Steven Bister
12,011 Points

Stuck 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 Parker
Steven Parker
221,900 Points

A link to the challenge would be very helpful.

Maddalena Menolascina
Maddalena Menolascina
6,668 Points

I performed the task 3 differently: $floatOne = 1.5; echo $integerOne * $floatOne; It worked for me

Thanks, Angel&Yle Meno&Frog, your answer worked for me also! Thank you!

11 Answers

Aaron Coursolle
Aaron Coursolle
18,014 Points

Create a new variable to assign to the formula and see if that will work.

Or you could even echo out the result of the multiplication directly without assigning to another variable.

Steven Bister
Steven Bister
12,011 Points

Hmm, 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!

Hi 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
Steven Bister
12,011 Points

Hi 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
Aaron Coursolle
18,014 Points

Thanks. You'll need to follow Jason's advice on a future challenge, so it's good that he stated it here.

<?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
osvaldo gonzalez
2,167 Points

$floatOne = 1.5; var_dump($integerOne * $floatOne); I keep this :Are you sure you multiplied correctly?

osvaldo gonzalez
osvaldo gonzalez
2,167 Points

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

Hi 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
Benjamin Blois
4,530 Points

Jason'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
vinayak sapkal
9,802 Points

$floatOne = 1.5; echo ( $intergerOne * $floatOne );

Victoria Loisi
Victoria Loisi
7,070 Points

Maybe the issue has anything to do with the space between the variable name and the -- operators? Instead of $integerTwo -- ; I would try $integerTwo-- ;

<?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?

Try taking out the var_dump for $integerOne and $integerTwo. It's making the final output incorrect.

I 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?

You 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
Jonathon Schloss
3,409 Points

Comment out your task 1 & 2 echo statements and it will pass!

those does not even have the correct answer, Please help coz Im still stucked.

Thanks

Mehedi Hasan
Mehedi Hasan
823 Points

This 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