User:Mr. Guye/odd-or-even.html

<!DOCTYPE html>  Odd or Even? Odd or Even? Enter a number and click the button to find out if the number is odd or even.  // Use a wrapping function to prevent global variables (function {                // Enable the strict mode (in short, it tells us some potential errors)                "use strict";

// You can select elements using document.querySelector var $result = document.querySelector(".result");

// Another way is using getElementById() var $input = document.getElementById("inputNumber"); var $btn = document.getElementById("runBtn");

// Append a click handler on the button $btn.addEventListener("click", function (event) {

// Validate the input if (!$input.value) { return alert("Please provide a number."); }

// When clicking on the button, take the value from input // Also convert it into a number var x = +$input.value;

// Create t a new variable that will contain the result // ("odd" or "event") var result;

// Check if the number is even if (x % 2 === 0) { result = "even"; } else { result = "odd"; }

// Tell the user if the number is odd or even $result.textContent = x.toString + " is " + result; });           });