logo CodeStepByStep logo

bmi

Language/Type: JavaScript parameters

Write a function named bmi that takes two Number values representing the weight and height of an individual. The function should calculate the body mass index (BMI), using the following formula:

BMI = weight / height2 * 703

The BMI rating groups each person into one of the following four categories:

BMI Category
below 18.5 class 1
18.5 - 24.9 class 2
25.0 - 29.9 class 3
30.0 and up class 4

After calculating the bmi and class for the given weight and height, your function should output the results, matching the following example output for the call to bmi(70.0, 194.25):

BMI = 27.9
class 3

Use the console.log() function to print each line of output and n.toFixed(1) to get a string of a number n to the precision of one decimal point. For example, if n is 1.2345, n.toFixed(1) would return "1.2".

Function: Write a JavaScript function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.