Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Even or Odd | Conditional Statements
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Introduction to JavaScript

bookChallenge: Even or Odd

Task

Swipe to start coding

Write code that determines whether a number is even or odd.
A number is even if it is fully divisible by 2. We can check this using the remainder operator (%).

For example:

  • 13 % 2 gives 1 β†’ not fully divisible β†’ odd.
  • 14 % 2 gives 0 β†’ fully divisible β†’ even.

We can use this property to distinguish between even and odd numbers.

Write the code inside the checkEvenOdd(num) function:

  • If the number is even β†’ make the message variable equal to "The number is even".
  • If the number is odd β†’ make the message variable equal to "The number is odd".

Use two different if statements to do this.

The result will be displayed automatically below the function.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 5
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

bookChallenge: Even or Odd

Swipe to show menu

Task

Swipe to start coding

Write code that determines whether a number is even or odd.
A number is even if it is fully divisible by 2. We can check this using the remainder operator (%).

For example:

  • 13 % 2 gives 1 β†’ not fully divisible β†’ odd.
  • 14 % 2 gives 0 β†’ fully divisible β†’ even.

We can use this property to distinguish between even and odd numbers.

Write the code inside the checkEvenOdd(num) function:

  • If the number is even β†’ make the message variable equal to "The number is even".
  • If the number is odd β†’ make the message variable equal to "The number is odd".

Use two different if statements to do this.

The result will be displayed automatically below the function.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 5
single

single

some-alt