Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: Even or Odd | Conditional Statements
Introduction to JavaScript

Glissez pour afficher le menu

book
Challenge: Even or Odd

Tâche

Swipe to start coding

Write a program which checks if the value inside the num variable is even or odd.

A number is even if it is fully divisible by 2. We can easily check this using the remainder operator (%).

For example:

  • 13 % 2 gives 1 which means it's not fully divisible by two, and therefore, it's an odd number.
  • 14 % 2 gives 0, which means it's fully divisible by two, and therefore, it's an even number.

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

Write the code to

  • Display the text "The number is even" if num is even.
  • Display the text The number is odd" if num is odd.

For this you'll need to write two different if-statements.

Think about what kind of boolean expression you can write to check if a number is even or odd.

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 5
Nous sommes désolés de vous informer que quelque chose s'est mal passé. Qu'est-il arrivé ?

Demandez à l'IA

expand
ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

book
Challenge: Even or Odd

Tâche

Swipe to start coding

Write a program which checks if the value inside the num variable is even or odd.

A number is even if it is fully divisible by 2. We can easily check this using the remainder operator (%).

For example:

  • 13 % 2 gives 1 which means it's not fully divisible by two, and therefore, it's an odd number.
  • 14 % 2 gives 0, which means it's fully divisible by two, and therefore, it's an even number.

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

Write the code to

  • Display the text "The number is even" if num is even.
  • Display the text The number is odd" if num is odd.

For this you'll need to write two different if-statements.

Think about what kind of boolean expression you can write to check if a number is even or odd.

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 5
Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Nous sommes désolés de vous informer que quelque chose s'est mal passé. Qu'est-il arrivé ?
some-alt