settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Imperial Units - convert from inches to feet and inches in JavaScript

+2 votes

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.

asked in JavaScript category by user mitko

1 Answer

+1 vote

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);

 

answered by user Jolie Ann
...