Hone logo
Hone
Problems

Is It Odd? A JavaScript Number Check

Ever wondered how computers tell if a number is odd or even? This fundamental skill is crucial for many programming tasks, from simple data filtering to complex algorithms. In this challenge, you'll build a JavaScript function to determine if a given number is odd.

Problem Description

Your task is to create a JavaScript function named isOdd that accepts a single argument, number. This function should return true if the number is odd, and false if it is even.

Key Requirements:

  • The function must be named isOdd.
  • It must accept one parameter: number.
  • It must return a boolean value: true for odd numbers, false for even numbers.

Expected Behavior:

  • If the input number is an odd integer (e.g., 1, 3, -5), the function should return true.
  • If the input number is an even integer (e.g., 0, 2, -4), the function should return false.

Edge Cases:

  • Consider the number 0. Is it odd or even?
  • Consider negative numbers. How should your function handle them?

Examples

Example 1:

Input: 7
Output: true
Explanation: 7 is an odd number.

Example 2:

Input: 4
Output: false
Explanation: 4 is an even number.

Example 3:

Input: -3
Output: true
Explanation: -3 is an odd number.

Example 4:

Input: 0
Output: false
Explanation: 0 is considered an even number.

Constraints

  • The input number will always be an integer.
  • The input number will be within the standard JavaScript number range.

Notes

The most common way to check for odd or even numbers involves the modulo operator. Think about what the modulo operator returns when a number is divided by 2. This will be a key clue to solving this problem efficiently.

Loading editor...
javascript