My Javascript code (in an HTML document) returns no output. Without the if
/else
, it functions, but even a simple if
does not work.
Goal: Find out HTML input value's modulus, and return even if 0 and odd if anything else.
Code(s):
HTML Input + Button:
<input id="num" type="number" min="1" name="num">
<button onclick="calculate(); evenodd(); return false;">Go</button>
(The calculate()
is another JS function, which works perfectly)
HTML Output:
<p id="evod"></p>
Javascript:
<script type="text/javascript">
function evenodd () {
var num2 = parseInt(document.getElementById("num").value);
if (num2 % 2) == 0) {
document.getElementById("evod").innerHTML = "Even";
}
else {
document.getElementById("evod").innerHTML = "Odd";
}
}
</script type="text/javascript">
</script>
evenodd()
even run? Try a console.log maybe? You've got another function there calledcalculate()
, and if that doesn't exist (which, according to the code you provided, it doesn't), I don't think the next function would execute.calculate()
exists, just that I did not provide it.