• 0

Determine if a number is Odd or not

Problem description :

Write a method to determine the given number is odd or not.
If it's not a number then throw an error.
Add this method as native javascript method.

Input : A number

Output : Boolean

Logic :

  • Check the given argument is a number or not.
  • If its a number then divide the number by 2,
    • If the remainder is +1, -1 then return true.

Solution :


We can add this method as a native javascript method on the Number.