I have a form with two inputs and a button. When button is clicked, calls a JavaScript function and multiply the two values from inputs. Then show the result in a <p>
element and is evaluated in a if else conditional to show a letter depending on value.
function showResult() {
var input1 = document.getElementById('input1');
var input2 = document.getElementById('input2');
var z = input1.value * input2.value;
var y = document.getElementById('result');
y.innerHTML = y.innerHTML + z;
var exp = document.getElementById('expression');
if (z < 100) {
expression.innerHTML = "A";
} else if (100 <= z <= 112.99) {
expression.innerHTML = "B";
} else if (113 <= z < 300.0) {
expression.innerHTML = "C";
} else {
expression.innerHTML = "D";
}
}
<form action="">
<input type="text" id="input1">
<input type="text" id="input2">
<button type="button" onclick="showResult();">Result</button>
</form>
<div>
<p id="result">The result is:</p>
<p id="expression"></p>
</div>
Here is the link to fiddle:
What is wrong?