Hone logo
Hone
Problems

Even Number Checker

Writing code to determine if a number is even is a fundamental skill in programming. This challenge will help you solidify your understanding of basic arithmetic operations and conditional logic in JavaScript. Being able to identify even numbers is a building block for many more complex algorithms and data processing tasks.

Problem Description

Your task is to create a JavaScript function that takes a single integer as input and returns a boolean value indicating whether the number is even or not.

Requirements:

  • The function should be named isEven.
  • It must accept one argument, which is expected to be an integer.
  • If the input number is even, the function should return true.
  • If the input number is odd, the function should return false.

Expected Behavior:

The function should accurately distinguish between even and odd integers.

Edge Cases to Consider:

  • Zero (0)
  • Negative integers

Examples

Example 1:

Input: 4
Output: true
Explanation: 4 is divisible by 2 with no remainder, so it's an even number.

Example 2:

Input: 7
Output: false
Explanation: 7 divided by 2 leaves a remainder of 1, so it's an odd number.

Example 3:

Input: 0
Output: true
Explanation: 0 is considered an even number as it is divisible by 2 with no remainder.

Example 4:

Input: -6
Output: true
Explanation: -6 is divisible by 2 with no remainder (-6 / 2 = -3), so it's an even number.

Constraints

  • The input will be a valid integer. You do not need to handle non-numeric inputs or floating-point numbers for this challenge.
  • The magnitude of the integer will not exceed standard JavaScript number limits.

Notes

Consider the mathematical definition of an even number. What operation can reveal if a number is perfectly divisible by another? Think about how you can check for a remainder after division.

Loading editor...
javascript