Skip to main content

This script works fine on desktop but won’t work on mobile and gives me no errors in the console.


Here is my html:


<p><select id="feet">
<option value="0">0</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select> feet <select id="inches">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="3">4</option>
<option value="3">5</option>
<option value="3">6</option>
<option value="3">7</option>
<option value="3">8</option>
<option value="3">9</option>
<option value="3">10</option>
<option value="3">11</option>
</select> inches <select id="weight">
<option value="0">0</option>
<option value="100">100</option>
<option value="105">105</option>
<option value="110">110</option>
<option value="115">115</option>
<option value="120">120</option>
<option value="125">125</option>
<option value="130">130</option>
<option value="135">135</option>
<option value="140">140</option>
<option value="145">145</option>
<option value="150">150</option>
<option value="155">155</option>
<option value="160">160</option>
<option value="165">165</option>
<option value="170">170</option>
<option value="175">175</option>
<option value="180">180</option>
<option value="185">185</option>
<option value="190">190</option>
<option value="195">195</option>
<option value="200">200</option>
<option value="205">205</option>
<option value="210">210</option>
<option value="215">215</option>
<option value="220">220</option>
<option value="225">225</option>
<option value="230">230</option>
<option value="235">235</option>
<option value="240">240</option>
<option value="245">245</option>
<option value="250">250</option>
</select> lbs. <input id="submit-btn" type="submit" value="Enter"></p>
<h3>BMI: <span id="output">0</span></h3>

And here is the javascript:


function computeBMI() {
//Obtain user inputs
var feet = Number(document.getElementById("feet").value);
var inches = Number(document.getElementById("inches").value);
var weight = Number(document.getElementById("weight").value);

var height = Number(inches + (feet * 12));

//Perform calculation
var BMI = weight / Math.pow(height,2);
var BMI = BMI * 703;

//Display result of calculation
document.getElementById("output").innerText = Math.round(BMI * 100)/100;
}

document.getElementById("submit-btn").addEventListener("click", computeBMI);
Be the first to reply!

Reply