Checking Oddish and Evenish numbers - JavaScript


A number is Oddish if the sum of all of its digits is odd, and a number is Evenish if the sum of all of its digits is even.

We are required to write a function that determines whether a number is Oddish or Evenish. We should return true of Oddish values and false for evenish

Example

Following is the code −

const num = 434667;
const isOddish = (num, sum = 0) => {
   if(num){
      return isOddish(Math.floor(num / 10), sum + (num % 10));
   };
   return sum % 2 === 1;
};
console.log(isOddish(num));

Output

Following is the output in the console −

false

Updated on: 16-Sep-2020

181 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements