logo CodeStepByStep logo

inchesToCentimeters

Language/Type: JavaScript basics expressions variables

Write a function named inchesToCentimeters that takes two parameters: a number of feet (ft) and a number of inches (in). The function should convert these values into centimeters and return the result. Note that there are 2.54 centimeters per inch, and 12 inches per foot.

For example, the call inchesToCentimeters(5, 11) should return 180.34 (from (5 * 12 + 11) * 2.54).

If either argument passed is negative, throw an exception with the message, "values for feet and inches must be non-negative".

Type your JavaScript solution code here:


This is a function exercise. Write a JavaScript function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.