[Solved] Numbers within strings? [closed]


The problem here is that weight and height are dom element references not their values, to get their value you need to read the value property

so

(function() {
  var btn = document.getElementById('btn'),
    bmiForm = document.getElementById('bmi-form'),
    weight = document.getElementById('weight'),
    height = document.getElementById('height');

  btn.onclick = function(e) {
    var bmi = weight.value / (height.value * height.value)
    alert(bmi);

    //to prevent the form submission
    e.preventDefault();
  }
})();
<form id="bmi-form">
  <input id="weight" />
  <input id="height" />
  <button type="submit" id="btn">Test</button>
</form>

1

solved Numbers within strings? [closed]