<< Back

Exercise 1.1 - Buttons and Inputs

b) Odd or even

This is the console. All output created with writeLog() is shown here.

Please type a number and press "Check odd or even". I will let you know whether the number is odd or even.


script.js

This is the JavaScript code behind the above application.

/* global writeLog, getInput */
writeLog("Solution for exercise 1.1 b)");
function checkOddOrEven() {
// Get the value from the input field
var number = getInput("theNumber");
writeLog("You entered the following number: " + number);
// Check if the number is odd or even
if (number % 2 === 0) {
writeLog("The number is even.");
}
else {
writeLog("The number is odd.");
}
}