QP School

Full Version: JavaScript exercises and solutions - Identify if a number is odd or even
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The HTML part between the <body></body> tags looks like this:

Code:
Please enter a number here:
<br>
<input type="Text" id="Num1">
<br>
<input type="button" id="submit" value="submit" onclick="oddOrEven()"></input>
<p id="Output"></p>
<input type="button" id="reset" value="Reset" onclick="Reset()"></input>

The JavaScript part looks like this:

Code:
function oddOrEven()
{
  Num1 = document.getElementById("Num1").value;
 
  if(Num1 % 2 == 0)
    {
      document.getElementById("Output").innerHTML = "Even";
    }
  else
    {
      document.getElementById("Output").innerHTML = "Odd";
    }
}

function Reset()
{
  document.getElementById("Num1").value = "";
  document.getElementById("Output").innerHTML = "";
}