ConvertersLesson 324Free preview
Convert Length
This lesson is part of How To · All levels
Summary
The length converter makes it easy to transfer values between meters, centimeters, kilometers, inches, feet, and miles. The most neat way is to convert all units to base units first, and then convert to target units. A consistent conversion factor prevents errors when adding a new unit option.
Key points
- One meter is equal to 100 centimeters.
- One inch is equal to 2.54 centimeters.
- One foot is equal to 0.3048 meters.
- One mile is equal to 1,609,344 meters.
- Save the conversion factor in the object so that the code can be easily expanded
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.