settingsAccountsettings
Menusettings

Q: How to check if number is even in Javascript?

+4 votes

I need to write a script to check if particular number is even in Javascript (with true or false booleans)

asked in JavaScript category by user hues
retagged by user golearnweb

2 Answers

+3 votes

Here's one simple solution:

function isEven(num) {
    return num % 2 === 0;
}

and a short video with embedded javascript in html:

answered by user icabe
edited by user golearnweb
+3 votes

another one:

function isEven(num) {
    if (num % 2 === 0) {
        return true;
    } else {
        return false;
    }
}

 

answered by user john7
...