1. Start
2. Declare a variable named kilometers and initialize it with the value to be converted
3. Declare a constant named KILOMETER_TO_MILE_RATIO and set it to 0.621371 (conversion factor)
4. Declare a variable named miles and calculate its value by multiplying kilometers with KILOMETER_TO_MILE_RATIO
5. Display the result: "X kilometers is equal to Y miles", where X is the original value in kilometers, and Y is the calculated value in miles
6. End

Code Examples

#1 Code Example- Kilometers to Miles

Code - Javascript Programming

// taking kilometers input from the user
const kilometers = prompt("Enter value in kilometers: ")

// conversion factor
const factor = 0.621371

// calculate miles
const miles = kilometers * factor

console.log(`${kilometers} kilometers is equal to ${miles} miles.`);
Copy The Code & Try With Live Editor


Enter value in kilometers: 2.2
2.2 kilometers is equal to 1.3670162000000001 miles.


JavaScript Programing Example to Convert Kilometers to Miles-DevsEnv

JavaScript Practice Example #3 - Assign 3 Variables and Print Good Way