Created
October 25, 2017 12:22
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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