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

Ben Os
Ben Os
20,008 Points

I believe I found a bug in the PHP basics course

Hello Alena Holligan , I think I found a bug in task 3 of this exercise:

https://teamtreehouse.com/library/php-basics-2/unit-converter/manipulating-numbers

The error I get is: "Are you sure you multiplied $integerOne by $floatOne? This should be the same as 6*1.5 which equals 9."

While my code is:

<?php

//Place your code below this comment

// Task One:
  $integerOne = 1;
  $integerTwo = 2;

// Task two:
  $integerOne += 5;
  $integerTwo -= 1;

  echo $integerOne;
  echo $integerTwo;

// Task three:

$floatOne = 1.5;
echo $integerOne * $floatOne;

?>

I also tried to put the multiplication in a "result" variable (I thought this is an expected architecture) but I still have the same error.

There is a another error, but a similar problem when two first echos are var_dumps.

Brian Retterer , Phil Sturgeon

1 Answer

andren
andren
28,558 Points

The issue is that the challenge judges your code entirely by looking at the output that your code generates. It expects it to output 9, but your code outputs 619.

This is due to the fact that in addition to using echo to show the result of $integerOne * $floatOne you also use echo earlier in the code to display the contents of $integerOne and $integerTwo. Which is not something the challenge asked you to do.

If you remove those additional echo statements like this:

<?php

//Place your code below this comment

// Task One:
  $integerOne = 1;
  $integerTwo = 2;

// Task two:
  $integerOne += 5;
  $integerTwo -= 1;

  // Removed two echo statements from this section

// Task three:

$floatOne = 1.5;
echo $integerOne * $floatOne;

?>

Then your code will work. Challenges are very picky, so adding anything not explicitly asked for will often lead to the challenge failing even if your code is otherwise correct.

Ben Os
Ben Os
20,008 Points

Oh, this is quite strange because even when these where printed via var_dump, it still didn't work... But when I removed the echo (or var_dumps) it did work. Thank you!

Alena Holligan
Alena Holligan
Treehouse Teacher

yes, you cannot add anything else to the output. Having an additional echo or var_dump will not give the desired results. It's always a good idea to remove that extra output, you wouldn't want that showing in production. Trust me I know ;)