Even Digits Only

Description


Check if all digits of the given integer are even.

Example

  • For n = 248622, the output should be evenDigitsOnly(n) = true;
  • For n = 642386, the output should be evenDigitsOnly(n) = false.

Input/Output

  • [execution time limit] 4 seconds (js)

  • [input] integer n

Guaranteed constraints: 1 \leq n \leq 10^9.

  • [output] boolean

true if all digits of n are even, false otherwise.

[JavaScript (ES6)] Syntax Tips

1
2
3
4
5
6
// Prints help message to the console
// Returns a string
function helloWorld(name) {
    console.log("This prints to the console when you Run Tests");
    return "Hello, " + name;
}

Solution


1
2
3
function evenDigitsOnly(n) {
    return String(n).split('').every(d=>d%2==0)
}