JavaScript program to calculate Body Mass Index (BMI)
The Body Mass Index (BMI) is a quick way to assess your body size simply with your weight and height, regardless of your gender. Quickly calculate your BMI and find out which category you fall into.The Body Mass Index (BMI) is the only index validated by the World Health Organization to assess an individual’s build and therefore health risks. The BMI makes it possible to determine whether one is the situation of thinness, overweight or obesity for example.In this program we will calculate BMI. Body mass index (BMI) is a measure of body fat based on height and weight that applies to adult men and women.Online Preview:Write a program that calculates and displays a person’s body mass index javaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | <!DOCTYPE html> <html lang="en-US"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title> CODE4EXAMPLE </title> <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"> <style> #vki{ transition: 1s all; } </style> </head> <body> <div class="container"> <h1>JavaScript BODY MASS INDEX (BMI)</h1> <form> <div class="form-group"> <label for="height">Please Enter your Height in Inches :</label> <input type="text" class="form-control" id="height" placeholder="69"> </div> <div class="form-group"> <label for="weight">Please Enter your weight in Pounds :</label> <input type="text" class="form-control" id="weight" placeholder="150"> </div> </form> <div class="alert alert-primary" role="alert" id="bmi"> Body Mass Index </div> </div> <script> const height =document.querySelector("#height") const weight =document.querySelector("#weight") const vki =document.querySelector("#vki") height.addEventListener('input',vkiHesapla); weight.addEventListener('input',vkiHesapla); function vkiHesapla() { h=height.value w=weight.value index = w/(h*h)* 703; index=index.toFixed(2) if (index < 18.5) { bmi.innerHTML="underweight - BMI : " + index bmi.setAttribute("class","alert alert-secondary") } else if (index < 25) { bmi.innerHTML="normal - BMI : "+ index bmi.setAttribute("class","alert alert-success") } else if (index < 30) { bmi.innerHTML="overweight - BMI : " + index bmi.setAttribute("class","alert alert-warning") } else { bmi.innerHTML="obese - BMI : " + index bmi.setAttribute("class","alert alert-danger") } } </script> </body> </html> |
You May Also Like:
[…] 💪 Basic BMI Calculator HTML/Javascript […]
[…] 💪 Basic BMI Calculator HTML/Javascript […]