javascript - What's wrong with this code to find heightInInches? -
after click, calculated bmi shown 0.3; expected answer 22.8
code snippet in question:
calculatebutton.addeventlistener('click', function() { var feet = feetfield.value; var inches = inchesfield.value; var heightininches = (feet * 12) + inches; bmidisplay.text = ((weightfield.value / (heightininches * heightininches)) * 703).tofixed(1); });
heightininches should equal 68, not 608. seems somehow feet (5) being multiplied 120 instead of 12 , tacking on inches (8) @ end, don't quite understand why that's happening, , why it's hiding me when step through code?
debugger shows correct values feet(5) , inches(8) in formula incorrect value assigned heightininches after calculation.
i think formatted question correctly; long time listener, first time caller. i've been staring @ long... had screenshots of ui , debugger had remove images post. ok, checking out.
try adding:
var feet = parsefloat(feetfield.value); var inches = parsefloat(inchesfield.value);
Comments
Post a Comment