export const take = [
{ label: "Weight", type: "unit", options: ["kg", "lbs"], unit: "kg" },
{ label: "Height", type: "unit", options: ["cm", "ft in"], unit: "cm" },
]
export const make = ([kg, cm]) => {
if (!kg || !cm) return "Add your weight and height to calculate your BMI."
const bmi = kg / Math.pow(cm / 100, 2)
const limits = [18.5, 25, 30]
const ranges = ["underweight", "normal weight", "overweight", "obese"]
let index = 0
while (bmi > limits[index]) index++
const min = limits[0] * Math.pow(cm / 100, 2)
const max = limits[1] * Math.pow(cm / 100, 2)
const detail = [
`Your BMI is in the <strong>${ranges[index]}</strong> range.`,
`<br>For someone of your height, the normal weight range is between`,
`${+min.toFixed(1)}–${+max.toFixed(1)}kg.`,
].join(" ")
return {
type: "card",
value: +bmi.toFixed(1),
detail,
}
}