File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change 11document . getElementById ( "btn" ) . addEventListener ( "click" , function ( ) {
2- var height_val = document . getElementById ( 'height' ) . value ;
3- var weight_val = document . getElementById ( 'weight' ) . value ;
4- var bmi = weight_val / ( height_val / 100 * height_val / 100 ) ;
5- var bmio = ( bmi . toFixed ( 2 ) ) ;
2+ var height_val = document . getElementById ( 'height' ) . value ; // in cm
3+ var weight_val = document . getElementById ( 'weight' ) . value ; // in kg
64
7- document . getElementById ( "result" ) . innerHTML = "Your BMI is " + bmio ;
8- } ) ;
5+ // Convert height from cm to m
6+ var height_in_m = height_val / 100 ;
7+
8+ // Calculate BMI
9+ var bmi = weight_val / ( height_in_m * height_in_m ) ;
10+
11+ // Round BMI to 2 decimal places
12+ var bmio = bmi . toFixed ( 2 ) ;
13+
14+ document . getElementById ( "result" ) . innerHTML = "Your BMI is " + bmio ;
15+ } ) ;
You can’t perform that action at this time.
0 commit comments