Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
JavaScript exercises and solutions - Identify if a number is odd or even
#1
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 = "";
}
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  JavaScript exercises and solutions - Swap two numbers Qomplainerz 0 290 04-04-2023, 07:54 AM
Last Post: Qomplainerz
  JavaScript exercises and solutions - Iterating through an array with keys and values Qomplainerz 0 317 04-04-2023, 07:52 AM
Last Post: Qomplainerz
  Check if an array contains a number in JavaScript Qomplainerz 0 254 04-04-2023, 07:12 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 4 Guest(s)