javascriptbeginner10 minutes

Build a Function to Check if a Number is Even

Create a simple JavaScript function that takes a number as input and returns true if the number is even, and false if it is odd.

Challenge prompt

Write a function named isEven that accepts one parameter, a number. The function should return true if the number is even, and false if the number is odd.

Guidance

  • Recall that a number is even if it is divisible by 2 with no remainder.
  • Use the modulus operator (%) to find the remainder when dividing the number by 2.
  • Return true if the remainder is 0; otherwise, return false.

Hints

  • Try using 'number % 2' — what does it return for even numbers?
  • Remember that the function should return a boolean value, true or false.
  • Test your function with both even and odd numbers to verify it works correctly.

Starter code

function isEven(number) {
  // Your code here
}

Expected output

isEven(4) // true isEven(7) // false

Core concepts

functionsconditionalsmodulus operator

Challenge a Friend

Send this duel to someone else and see if they can solve it.