javascript - Code modifying to identify category in html code -
OK, I need to modify the code that is able to identify which category of the user.
- Lose weight below 18.5
- Normally 18.5 to 25
- 25-30 more weight
- More than 30 obesity
And then finally I need to know which category the user is in and displays: This means that you (underweight, general, etc.)
< P> Thanks & lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; BMI calculator & lt; / Title & gt; & Lt; Script type = "text / javascript" & gt; Function computeBMI () {// user inputs var height = get number (document.getElementById ("height"). Value); Varheightunits = document.getElementById ("heightunits") value Var weight = number (document.getElementById ("weight"). Value); Varweightunits = document.getElementById ("weightunits") value. // Convert all units to metric if height (= = "inch") height = / 39.3700787; If (weight components == "lb") weighs / = 2.20462; // Calculate var BMI = weight / Math.pow (height, 2); // display result of calculation document GetElementById ("Output"). InnerText = MathRed (BMI * 100) / 100; } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; H1 & gt; Body Mass Index Calculator & lt; / H1> & Lt; P & gt; Enter your height: & lt; Input type = "article" id = "height" /> & Lt; Select Type = "Multiple" id = "heightunits" & gt; & Lt; Option value = "meters" selected = "selected" & gt; Meter & lt; / Options & gt; & Lt; Option value = "inch" & gt; Inch & lt; / Options & gt; & Lt; / Select & gt; & Lt; / P & gt; & Lt; P & gt; Enter your weight: & lt; Input type = "article" id = "weight" /> & Lt; Select type = "multiple" id = "weightunits" & gt; & Lt; Option value = "kg" selected = "selected" & gt; Kilograms & lt; / Option & gt; & Lt; Option value = "lb" & gt; £ & lt; / Options & gt; & Lt; / Select & gt; & Lt; / P & gt; & Lt; Input type = "submit" value = "computeBMI" onclick = "computeBMI ();" & Gt; & Lt; H1 & gt; Your BMI is: & lt; Span id = "Output" & gt; & Lt; / Span & gt; & Lt; / H1> & Lt; / Body & gt; & Lt; / Html & gt;
Add this row to your HTML, it may be and Lt; H1 & gt;
Tags:
& lt; Span id = "id_here" & gt; & Lt; / Span & gt;
Any other element will work unless it has an ID.
Then you add it to your JS:
var typing = document. GetElementById ("id_of_the_element_below_h1"); If (Answer <18.5) {writeThere.innerText = "You are underweight"; } And if (Answer> 18.5 & amp; amp; amp;; ans & lt; 25) {writeThere.innerText = "You are normal"; } And if (Answer> 25 & amp; & amp;; & amp;; ans & lt; 30) {writeThere.innerText = "You are overweight"; } And {writeThere.innerText = "You are fat"; }
You can say that where the variable ans is, it can be right here:
var ans = Math.round (BMI * 100) / 100; // display result of calculation document GetElementById ("Output"). InnerText = ans;
Comments
Post a Comment