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 Creating a Unit Conversion Tool

Sean Flanagan
Sean Flanagan
33,235 Points

My solution for converting kg to lbs and km to miles

Hi. Have I got this right?

// kg to convert to lbs
$kg = 50;
// floating-point value for kg-lb conversion
$kg_to_lb = 0.453592;
// use the variables to calculate conversion
$lb = $kg_to_lb / $kg;
// display lb equivalent
echo "Weight: ";
echo " kg = ";
echo $lb;
echo " lb ";

// number of km to convert to miles
$km = 5;
// floating point value for km-mile conversion
$km_to_miles = 1.60934;
// use the variable above to convert km to miles
$miles = $km / $km_to_miles;
// display equivalent in miles
echo "Distance: ";
echo $km;
echo " km = ";
echo $miles;
echo " miles ";

Thanks in advance.

Feel free to offer constructive feedback and share your own solutions.