Introduction
In this lab, we will explore how to convert miles to kilometers using JavaScript. The purpose of this lab is to help you understand the conversion formula and apply it to a real-world scenario. By the end of this lab, you will be able to write a function that converts miles to kilometers, which can be useful in a variety of applications.
Conversion of Miles to Kilometers
To convert miles to kilometers, follow these steps:
- Open the Terminal/SSH and type
nodeto start practicing coding. - Use the conversion formula
km = mi * 1.609344. - Implement the formula using the JavaScript code below:
const milesToKm = (miles) => miles * 1.609344;
- Test the function by calling it with the desired number of miles, like this:
milesToKm(5); // ~8.04672
This will return the equivalent distance in kilometers.
Summary
Congratulations! You have completed the Miles to Km lab. You can practice more labs in LabEx to improve your skills.