Facebook
From xxx, 6 Years ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 266
  1. <html>
  2.     <head>
  3.         <title>Body Mass Index</title>
  4.         <meta charset="UTF-8">
  5.         <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.         <style>
  7.             .wynik{
  8.                 height: 150px;
  9.                 width: 400px;
  10.                 margin: 0 auto;
  11.                 background-color: gray;
  12.                 color: white;
  13.                 font-size: 30px;
  14.                 line-text: 150px;
  15.             }
  16.         </style>
  17.     </head>
  18.     <body>
  19.         <div><h3>Body Max Index</h3></div>
  20.         <br><br><br><br>
  21.  
  22.         <div class="wynik">
  23.  
  24.  
  25.             <script>
  26.                 var masa = prompt("Podaj masę ciała");
  27.                 var wzrost = prompt("Podaj wzrost w cm");
  28.                 var bmi;
  29.                 var txt = "";
  30.  
  31.                 console.log("masa = " + masa);
  32.                 console.log("wzrost = " + wzrost);
  33.  
  34.                 if (wzrost == "" || masa == "" || wzrost == null || masa == null) {
  35.                     document.write("nie wpisałeś jakiejś zmiennej");
  36.                 } else {
  37.  
  38.                     var pomoc = wzrost - 1;
  39.                     console.log("wzrost = " + pomoc);
  40.                     if (isNaN(pomoc)) {
  41.                         txt = "Wzrost to nie jest liczba!";
  42.                     }
  43.  
  44.                     // pomoc = parseInt(masa);
  45.                     pomoc = masa - 1;
  46.                     console.log("masa = " + pomoc);
  47. //                    if (pomoc == "NaN") {
  48.                     if (isNaN(pomoc)) {
  49.                         txt = txt + " Waga nie jest liczbą!";
  50.                     }
  51.  
  52.                     if (txt.lenght > 0) {
  53.                         document.write(txt);
  54.                     } else {
  55.  
  56.                         wzrost = wzrost / 100;
  57.                         bmi = masa / (wzrost * wzrost);
  58.                         console.log(bmi);
  59.  
  60.                         if (bmi < 18.5) {
  61.                             txt = "Masz niedowagę";
  62.                         } else if (bmi < 25) {
  63.                             txt = "Twoja waga jest prawidłowa";
  64.                         } else if (bmi >= 25.00) {
  65.                             document.write("Masz nadwagę!!");
  66.                         }
  67.                         document.write(txt + " BMI równa się " + bmi.toFixed(2));
  68.                     }
  69.                 }
  70.  
  71.             </script>
  72.         </div>
  73.     </body>
  74. </html>
  75.