{"id":1592,"date":"2016-08-17T09:00:32","date_gmt":"2016-08-17T09:00:32","guid":{"rendered":"http:\/\/javascript-tutor.net\/?p=1592"},"modified":"2017-09-21T13:34:23","modified_gmt":"2017-09-21T13:34:23","slug":"bmi-calculator","status":"publish","type":"post","link":"https:\/\/javascript-tutor.net\/index.php\/2016\/08\/17\/bmi-calculator\/","title":{"rendered":"BMI Calculator"},"content":{"rendered":"<p>You can create a BMI calculator using JavaScript. The formula for BMI(Body Mass Index) is as follows:<\/p>\n<p><strong>BMI=weight\/(height)^2<\/strong><\/p>\n<p>where weight is in kg and height in cm.<\/p>\n<p>In the\u00a0html page, you can create three text box using the &lt;input&gt; tag to accept the user inputs for name, height and weight.<\/p>\n<p>In the JavaScript, you can create a function to calculate the bmi, as follows:<\/p>\n<p>function bmi(){<\/p>\n<p>var sheight=parseFloat(document.getElementById(&#8216;hgt&#8217;).value);<br \/>\nvar sweight=parseFloat(document.getElementById(&#8216;wgt&#8217;).value);<br \/>\nvar bmi=sweight\/Math.pow(sheight,2);<br \/>\nvar student_bmi=document.getElementById(&#8216;bmi_index&#8217;);<br \/>\nstudent_bmi.textContent=bmi.toFixed(2);<br \/>\n}<\/p>\n<ul>\n<li>toFixed method is to round the output to 2 decimal ppalces<\/li>\n<\/ul>\n<p>The html document is<\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;body&gt;<\/p>\n<p>&lt;h1&gt;Student Name=&lt;input type=&#8221;text&#8221; style=&#8221;font-size:25px; font-weight: bold;&#8221; id=&#8221;studentname&#8221;&gt;&lt;\/h1&gt;<br \/>\n&lt;h2&gt;Height=&lt;input type=&#8221;text&#8221; style=&#8221;font-size:20px; font-weight: bold;&#8221; id=&#8221;hgt&#8221;&gt;&lt;\/h2&gt;<br \/>\n&lt;h2&gt;Weight=&lt;input type=&#8221;text&#8221; style=&#8221;font-size:20px; font-weight: bold;&#8221; id=&#8221;wgt&#8221;&gt;&lt;\/h2&gt;<br \/>\n&lt;h2&gt;BMI=&lt;b id=&#8221;bmi_index&#8221;&gt;&lt;\/b&gt;&lt;\/h2&gt;<\/p>\n<p>&lt;input type=&#8221;button&#8221; value=&#8221;Calculate&#8221; onclick=&#8221;bmi()&#8221;&gt;<br \/>\n&lt;script type=&#8221;text\/javascript&#8221; src=&#8221;bmi2.js&#8221;&gt;&lt;\/script&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<p>Click <a href=\"http:\/\/javascript-tutor.net\/jSample\/bmi2.html\">here<\/a> to launch the BMI calculator<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can create a BMI calculator using JavaScript. The formula for BMI(Body Mass Index) is as follows: BMI=weight\/(height)^2 where weight is in kg and height in cm. In the\u00a0html page, you can create three text box using the &lt;input&gt; tag to accept the user inputs for name, height and weight. In the JavaScript, you can &hellip; <a href=\"https:\/\/javascript-tutor.net\/index.php\/2016\/08\/17\/bmi-calculator\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;BMI Calculator&#8221;<\/span><\/a><\/p>\n","protected":false},"author":35895,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1592","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>BMI Calculator - Learn JavaScript Online | Free Interactive JavaScript Tutorials<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/javascript-tutor.net\/index.php\/2016\/08\/17\/bmi-calculator\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"BMI Calculator - Learn JavaScript Online | Free Interactive JavaScript Tutorials\" \/>\n<meta property=\"og:description\" content=\"You can create a BMI calculator using JavaScript. The formula for BMI(Body Mass Index) is as follows: BMI=weight\/(height)^2 where weight is in kg and height in cm. In the\u00a0html page, you can create three text box using the &lt;input&gt; tag to accept the user inputs for name, height and weight. In the JavaScript, you can &hellip; Continue reading &quot;BMI Calculator&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/javascript-tutor.net\/index.php\/2016\/08\/17\/bmi-calculator\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn JavaScript Online | Free Interactive JavaScript Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2016-08-17T09:00:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-09-21T13:34:23+00:00\" \/>\n<meta name=\"author\" content=\"Liew Voon Kiong\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Liew Voon Kiong\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/2016\/08\/17\/bmi-calculator\/\",\"url\":\"https:\/\/javascript-tutor.net\/index.php\/2016\/08\/17\/bmi-calculator\/\",\"name\":\"BMI Calculator - Learn JavaScript Online | Free Interactive JavaScript Tutorials\",\"isPartOf\":{\"@id\":\"https:\/\/javascript-tutor.net\/#website\"},\"datePublished\":\"2016-08-17T09:00:32+00:00\",\"dateModified\":\"2017-09-21T13:34:23+00:00\",\"author\":{\"@id\":\"https:\/\/javascript-tutor.net\/#\/schema\/person\/63d832c3efdf443517b5f5bfd1b93df8\"},\"breadcrumb\":{\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/2016\/08\/17\/bmi-calculator\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/javascript-tutor.net\/index.php\/2016\/08\/17\/bmi-calculator\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/2016\/08\/17\/bmi-calculator\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/javascript-tutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"BMI Calculator\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/javascript-tutor.net\/#website\",\"url\":\"https:\/\/javascript-tutor.net\/\",\"name\":\"Learn JavaScript Online | Free Interactive JavaScript Tutorials\",\"description\":\"Master JavaScript with free, interactive tutorials for beginners and experienced coders. Practice live coding and visualize how JavaScript works step by step.\",\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/javascript-tutor.net\/#\/schema\/person\/63d832c3efdf443517b5f5bfd1b93df8\",\"name\":\"Liew Voon Kiong\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/javascript-tutor.net\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/413ad70576fa5f43c1d3ae3429c92579c21f536c350e6470302fa25ddd9b6a13?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/413ad70576fa5f43c1d3ae3429c92579c21f536c350e6470302fa25ddd9b6a13?s=96&d=mm&r=g\",\"caption\":\"Liew Voon Kiong\"},\"url\":\"https:\/\/javascript-tutor.net\/index.php\/author\/ajt7051jct\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"BMI Calculator - Learn JavaScript Online | Free Interactive JavaScript Tutorials","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/javascript-tutor.net\/index.php\/2016\/08\/17\/bmi-calculator\/","og_locale":"en_US","og_type":"article","og_title":"BMI Calculator - Learn JavaScript Online | Free Interactive JavaScript Tutorials","og_description":"You can create a BMI calculator using JavaScript. The formula for BMI(Body Mass Index) is as follows: BMI=weight\/(height)^2 where weight is in kg and height in cm. In the\u00a0html page, you can create three text box using the &lt;input&gt; tag to accept the user inputs for name, height and weight. In the JavaScript, you can &hellip; Continue reading \"BMI Calculator\"","og_url":"https:\/\/javascript-tutor.net\/index.php\/2016\/08\/17\/bmi-calculator\/","og_site_name":"Learn JavaScript Online | Free Interactive JavaScript Tutorials","article_published_time":"2016-08-17T09:00:32+00:00","article_modified_time":"2017-09-21T13:34:23+00:00","author":"Liew Voon Kiong","twitter_misc":{"Written by":"Liew Voon Kiong","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/javascript-tutor.net\/index.php\/2016\/08\/17\/bmi-calculator\/","url":"https:\/\/javascript-tutor.net\/index.php\/2016\/08\/17\/bmi-calculator\/","name":"BMI Calculator - Learn JavaScript Online | Free Interactive JavaScript Tutorials","isPartOf":{"@id":"https:\/\/javascript-tutor.net\/#website"},"datePublished":"2016-08-17T09:00:32+00:00","dateModified":"2017-09-21T13:34:23+00:00","author":{"@id":"https:\/\/javascript-tutor.net\/#\/schema\/person\/63d832c3efdf443517b5f5bfd1b93df8"},"breadcrumb":{"@id":"https:\/\/javascript-tutor.net\/index.php\/2016\/08\/17\/bmi-calculator\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/javascript-tutor.net\/index.php\/2016\/08\/17\/bmi-calculator\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/javascript-tutor.net\/index.php\/2016\/08\/17\/bmi-calculator\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/javascript-tutor.net\/"},{"@type":"ListItem","position":2,"name":"BMI Calculator"}]},{"@type":"WebSite","@id":"https:\/\/javascript-tutor.net\/#website","url":"https:\/\/javascript-tutor.net\/","name":"Learn JavaScript Online | Free Interactive JavaScript Tutorials","description":"Master JavaScript with free, interactive tutorials for beginners and experienced coders. Practice live coding and visualize how JavaScript works step by step.","inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/javascript-tutor.net\/#\/schema\/person\/63d832c3efdf443517b5f5bfd1b93df8","name":"Liew Voon Kiong","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/javascript-tutor.net\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/413ad70576fa5f43c1d3ae3429c92579c21f536c350e6470302fa25ddd9b6a13?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/413ad70576fa5f43c1d3ae3429c92579c21f536c350e6470302fa25ddd9b6a13?s=96&d=mm&r=g","caption":"Liew Voon Kiong"},"url":"https:\/\/javascript-tutor.net\/index.php\/author\/ajt7051jct\/"}]}},"_links":{"self":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/posts\/1592","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/users\/35895"}],"replies":[{"embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/comments?post=1592"}],"version-history":[{"count":2,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/posts\/1592\/revisions"}],"predecessor-version":[{"id":1594,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/posts\/1592\/revisions\/1594"}],"wp:attachment":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=1592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=1592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=1592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}