Skip to content

Instantly share code, notes, and snippets.

@abdulhalim-cu
Created October 25, 2017 12:22
Show Gist options
  • Save abdulhalim-cu/4f85c780950628c8b21364c6bcf61700 to your computer and use it in GitHub Desktop.
Save abdulhalim-cu/4f85c780950628c8b21364c6bcf61700 to your computer and use it in GitHub Desktop.
We’ve seen that % (the remainder operator) can be used to test whether a number is even or odd by using % 2 to check whether it’s divisible by two. Here’s another way to define whether a positive whole number is even or odd
// Your code here.
function isEven(number){
while (number > 0 || number < 0)
if (number > 0 && (isEven(number - 1) == 0))
return true;
else if(number < 0 && (isEven(number + 1) == 0))
return true;
else
return false;
}
console.log(isEven(50));
// → true
console.log(isEven(-76));
// → false
console.log(isEven(-2));
// → ??
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment