![]() If (b = 18.5 & b 25 & b 30 & b 35 & b Īfter this step, you can access the BMI calculator module from the HTML file. Var b = w/(h*h) // According to the formulaĭocument.getElementById("ans").value = String(b.toPrecision(3)) +" kg/m^2" // writing to the output Var h = parseFloat(document.getElementById("height").value)/100 // Convert height to meters Var w = parseFloat(document.getElementById("weight").value) // To get weight from the input with id as weight ![]() We can classify the BMI into the following categories: Now we need to write a function named bmi to calculate the BMI of the user from the entered values. The interface looks like the below image: The function “document.write” is used to write to the HTML document in which the file “bmi.js” is included. Then write the following code to create an input interface for the user.Create a javascript file by the name of “bmi.js”.Now we should collect mass and height-related information as follows: So, our main goal is to collect information from the height, weight information from the user, and calculate body mass index by the following formula: How to make a BMI calculator using JavaScriptįirstly, what is the body mass index (BMI)?īody mass index ( BMI) is defined as the body mass divided by the square of the body height and is expressed in units of kg/m 2, resulting from mass in kilograms and height in meters. I am using Visual Studio Code for editing, you can use any editor you are comfortable with. The readers are suggested to use an editor while writing the code. Although a basic understanding of HTML and DOM ( Document Object Model ) will give you an edge. There are no specific pre-requisites for this tutorial. This tutorial will not only enhance your knowledge about BMI calculation but also provide a basic understanding of JavaScript. This module can be included in any of the HTML files with a single line of code. Example: 72.Hello! In this tutorial, we will be building a body mass index (BMI) calculator in JavaScript. Example: 178.5 pounds equals 178 pounds & 8 ounces: Let theString = "Your body mass index (BMI) is: " + getBMI ĭocument.getElementById("calcBMI").addEventListener("click", doCalcBMI()) Let myBMI = (theWeight / (theHeight * theHeight))*730 ĭocument.getElementById("bmiResult").innerHTML = myOutput(myBMI) Let theHeight = document.getElementById("myHeight").value Let theWeight = document.getElementById("myPounds").value I can't seem to get this to work and don't know where to go next. Personal blog posts that are relevant to the subreddit's stated subject matter don't need prior approval (and are encouraged!).įor an assignment of mine, I am supposed to create a program that displays an individual's BMI after they input numbers and hit the button. If you want to post something self-promotional, please message the mods first. Titles that begin with "hey guys" will be removed. If you're in doubt, message the mods first. The following are not allowed: Requests for subscribers, asking for "test users" for your new JS course, offering paid mentorships, and/or premium courses. The app does conversion of metric to standard measurements and standard to metric. If you’re asking for help, include enough information for others to recreate your problem. This is an HTML / JavaScript app for calculating someones body mass index. With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged. Everyone should feel comfortable asking any and all JavaScript questions they have here. This subreddit is a place for people to learn JavaScript together.
0 Comments
Leave a Reply. |