Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>BMI Calculator</title>
- <style>
- .container{
- margin:auto;
- width:60%;
- }
- .m-auto {
- margin:auto;
- }
- .w-50p{
- width: 50%;
- }
- </style>
- </head>
- <body>
- <div class="container" onsubmit="return false">
- <h1 class="text-center">Kalkulator BMI</h1>
- <br>
- <form action="">
- <input class="w-50p" id="height" type="text" placeholder="Masukkan tinggi badan(m)">
- <br>
- <br>
- <input class="w-50p" id="weight" type="text" placeholder="Masukkan berat badan(kg)">
- <br><br>
- <input type="submit" value="Hitung BMI" onclick="calculate()">
- <br>
- <br>
- <h2 id="result" class="text-center"></h2>
- </form>
- </div>
- <script>
- function calculate(){
- let height = parseInt(document.getElementById("height").value) * 2 ;
- let weight = document.getElementById("weight").value;
- let result = document.getElementById("result");
- let bmi = parseInt(weight) / height;
- console.log("berat: "+ weight)
- console.log("tinggi: "+ height)
- console.log(bmi);
- if(bmi < 18.5){
- result.innerHTML = "Underweight";
- // result.innerHTML = bmi;
- // console.log(bmi);
- } else if(bmi >= 18.5 && bmi < 25) {
- result.innerHTML = "Normal";
- // result.innerHTML = bmi;
- } else if(bmi >= 25 && bmi < 30){
- result.innerHTML = "Overweight";
- // result.innerHTML = bmi;
- } else if(bmi >= 30) {
- result.innerHTML = "Obesity"
- // result.innerHTML = bmi;
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment