Build a BMI calculator

luhan
Membro
Iscritto:
2024-07-18 16:23:16

Write a function that calculates a user BMI. BMI = weight/height^2 Your code should request for the user's weight and height and then return their bmi to them. Your return statement should be "[BMI]kg/m^2.

P.S: To simplify, use prompt and alert (depending on how your language calls it) when necessary and make sure your code is testable on the Google Chrome console (developer tool)

Image preview

mccall
Membro
Iscritto:
2024-07-19 13:33:12
```
const weight = prompt("Enter your weight");
const height = prompt("Enter your height");
const bmiCalc = () => {
const bmi = weight / Math.pow(height, 2);
return `Your BMI is ${bmi}kg/m^2`;
};
alert(bmiCalc());
```
Simplythebest
Membro
Iscritto:
2024-07-21 01:06:53

@"mccall"#p963 this looks interesting, this looks like ES 5 syntax right?

jenny
Membro
Iscritto: 2025-08-24 15:11:06
2024-07-21 01:15:54

The solution in python is:
`def bmi_calc(weight, height):`

` bmi = weight / (height ** 2)`

` return f"Your BMI is {bmi} kg/m^2"`

`weight = float(input("Enter your weight: "))`

`height = float(input("Enter your height: "))`

`print(bmi_calc(weight, height))`

luhan
Membro
Iscritto:
2024-07-21 07:27:45

@"mccall"#p963 this is correct 👍🏾. Worked fine on my console

luhan
Membro
Iscritto:
2024-07-21 07:30:11

@"Simplythebest"#p969 the variable declaration and arrow function are part of ES6 rules, I believe

luhan
Membro
Iscritto:
2024-07-21 07:32:41

@"dhtml"#p979 I am a JS developer but damn Python codes are so easy to read.

jenny
Membro
Iscritto: 2025-08-24 15:11:06
2024-07-25 10:35:55
[[31],[29]]
Facebook X (Twitter) Instagram LinkedIn Telegram WhatsApp