Join Kevin Skoglund for an in-depth discussion in this video Solution: Convert to and from metric area, part of Easy PHP Projects: Measurement Conversion.
- View Offline
- At the end of the last movie,…I presented a challenge to you,…to write the area conversions yourself using our code…for length conversions and what we also learned…about how area measurements work.…Hopefully you were able to get it to work on your own.…I'm now going to show you my solution…so you can compare your results with mine.…The first thing I did was I changed…our convert length function to be convert area,…both when we define it and when we call it.…The arguments that we pass in…are still going to be the same.…Then inside convert area I changed the name…of the two functions we're calling from convert to meters…and convert from meters, to become convert to square meters…and convert from square meters.…
Then, I changed the names of the functions up here…where we define them as well.…Next, I dove into each of these functions…and made some edits.…In convert to square meters, where we were looking for…the value of from unit in each of our cases,…it's no longer going to be inches,…instead now it's going to be square_inches.…
Along the way, series designer Kevin Skoglund introduces coding strategies, refactoring techniques, and useful skills including dynamically generating form select-option values and formatting decimal numbers and scientific notation.
- Converting length and area measurements
- Using functions to avoid repetition
- Refactoring to produce simpler code
- Converting volume and mass
- Generating form select-option values dynamically
- Formatting scientific notation
- Converting speed and temperature