💬 Showcase & Feedback

Build a BMI calculator

A

Anthony Olajide

Jan 2, 2026 at 2:56 PM

7 replies 525 views
Write a function that calculates a user BMI. BMI = weight/height[s]^[/s]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[s]^[/s]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

7 Replies

Sign in to join the conversation

A

Anthony Olajide

2 months ago
[s]```[/s]
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());
```
A

Anthony Olajide

2 months ago
@"mccall"#p963 this looks interesting, this looks like ES 5 syntax right?
d

diltony@yahoo.com

2 months ago
The solution in python is:
[s]`[/s]def bmi_calc(weight, height):`

[s]` [/s]bmi = weight / (height ** 2)`

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

[s]`[/s]weight = float(input("Enter your weight: "))`

[s]`[/s]height = float(input("Enter your height: "))`

[s]`[/s]print(bmi_calc(weight, height))`
A

Anthony Olajide

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

Anthony Olajide

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

Anthony Olajide

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

diltony@yahoo.com

2 months ago
[[31],[29]]