programming-examples/js/Recursion/Write a JavaScript program to check whether a number is even or not..js

23 lines
468 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
function is_even_recursion(number)
{
if (number < 0)
{
number = Math.abs(number);
}
if (number===0)
{
return true;
}
if (number===1)
{
return false;
}
else
{
number = number - 2;
return is_even_recursion(number);
}
}
console.log(is_even_recursion(234)); //true
console.log(is_even_recursion(-45)); // false
console.log(is_even_recursion(-45)); // false