3
06/11/2024 5:26 pm
Topic starter
Imperial units are confusing, but still in use in some backwards countries (Myanmar, Liberia and the United States are the only countries still using them). They are so confusing in fact, that native users struggle to convert between them.
Write a JavaScript function that converts from inches to feet and inches. There are 12 inches in a foot. See the example for formatting details. The input comes as a single number.
Examples:
Input:
36
Output:
3'-0"
Input:
55
Output:
4'-7"
Input:
11
Output:
0'-11"
The output should be printed to the console.
1 Answer
2
06/11/2024 5:26 pm
Here is my javascript code/program (12 inches = 1 foot):
function convertInches(inches) { let feetFromInches = Math.floor(inches / 12);//There are 12 inches in a foot let inchesRemainder = inches % 12; let result = feetFromInches + "'-" + inchesRemainder + "\""; console.log(result); } convertInches(55);