Beginner

Check if a Number is Even or Odd

Description

In this challenge, you will write a function that determines whether a given number is even or odd.

This is a fundamental problem in programming and can help users understand how to work with conditionals, functions, and the modulus (%) operator.

An even number is any number that is divisible by 2 without a remainder (e.g., 2, 4, 6, 8), while an odd number is any number that leaves a remainder of 1 when divided by 2 (e.g., 1, 3, 5, 7).

The function should:

Accept a single integer as input. Return "even" if the number is even, and "odd" if the number is odd.

Handle both positive and negative numbers. Assume the input is always a valid integer (no need to check for non-numeric values).

Example usage:

console.log(checkEvenOrOdd(10));
// Expected output: "even"
console.log(checkEvenOrOdd(7));
// Expected output: "odd"
console.log(checkEvenOrOdd(-4));
// Expected output: "even"

window code 2Test Cases

Input:

7

Expected Output:

"odd"