function solution(num) {
return num % 2 === 0 ? 'Even' : 'Odd'
}
function isEven(numbers) {
if (numbers % 2 == 0) {
return true;
}
return false;
}
var input = 22;
var result = isEven(input);
console.log(result)
//Outpur: true
// vanilla
function isEven(num) {
return num % 2 == 0;
}
function isOdd(num) {
return Math.abs(num % 2) == 1;
}
// ES6
const isEven = num => ((num % 2) == 0);
//bitwise AND operator
const isOdd = function(num) { return num & 1; };
const isEven = function(num) { return !( num & 1 ); };
const isEven = num => num % 2 === 0;
console.log(isEven(2));
// Result: True
function isOdd(numbers) {
if (numbers % 2 != 0) {
return true;
}
return false;
}
var input = 343;
var result = isOdd(input);
console.log(result)
//Outpur: true
for(var n = 0; n <= 10; n+=2) console.log(n)
const isEven = (num) => num % 2 === 0;
console.log(isEven(5));// falseconsole.log(isEven(4));// true
for(let count =0; count<=100;count++){
count%2==0? console.log(`${count} is even`):console.log(`${count} is odd`);
;
}
let arr = [1,2,3,4,5,6,7,8,9,10,11,12]
let odds = arr.filter(n => n%2)
console.log(odds)
Run code snippetHide results
const isOdd = n => !!(n & 1)