My BMI calculator works in Chrome, Firefox and Opera but not in IE. When I look at the IE Debugger, there are no errors. The problem is that the calculator doesn't show the result. I'm aware that my question is similar to this link Inline event handler not working in JSFiddle however, I can't understand the solution in relation to my problem.
Here is the javascript:
const form = document.querySelector('form[name=bmi]');
const onSubmit = event => {
event.preventDefault();
let healthMessage;
const result = form.querySelector('.result');
const health = form.querySelector('.health');
const weight = parseInt(form.querySelector('input[name=weight]').value, 10);
const height = parseInt(form.querySelector('input[name=height]').value, 10);
const bmi = (weight / (height /100 * height / 100)).toFixed(1);
if (bmi < 18.5) {
healthMessage = 'undervægtig';
} else if (bmi > 18.5 && bmi < 25) {
healthMessage = 'normal vægtig';
} else if (bmi > 25) {
healthMessage = 'overvægtig';
}
result.innerHTML = bmi;
health.innerHTML = healthMessage;
};
form.addEventListener('submit', onSubmit, false);
Here is the HTML:
<form name="bmi">
<h1>Mål dit BMI:</h1>
<label>
<input type="text" name="weight" id="weight" placeholder="Vægt (kg)">
<input type="text" name="height" id="height" placeholder="Højde (cm)">
<input type="submit" name="submit" id="submit" value="Udregn BMI">
</label>
<div class="calculation">
<div>
Dit BMI er: <span class="result"></span>
</div>
<div>
Dette betyder at du er: <span class="health"></span>
</div>
</div>
</form>
And here is a fiddle: https://jsfiddle.net/1nd7oot5/