![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements