This Even or Odd Checker code works by first taking the number entered by the user from the input field and storing it in a variable when the button is clicked. The program then uses the modulo operator (%) to divide the number by 2 and check the remainder; if the remainder is 0, the number is even, otherwise it is odd. Based on this condition, JavaScript updates the text of the result paragraph using document.getElementById().innerText to display whether the entered number is even or odd.
<!DOCTYPE html> <html> <body> <input type="number" id="number"> <button onclick="check()">Check</button> <p id="result"></p> <script src="script.js"></script> </body> </html>
function check() {
let num = document.getElementById("number").value;
if (num % 2 === 0) {
document.getElementById("result").innerText = "Even Number";
} else {
document.getElementById("result").innerText = "Odd Number";
}
}