Challenge: Even or Odd
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 % 2gives1β not fully divisible β odd.14 % 2gives0β 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
messagevariable equal to"The number is even". - If the number is odd β make the
messagevariable equal to"The number is odd".
Use two different if statements to do this.
The result will be displayed automatically below the function.
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 1.35
Challenge: Even or Odd
Swipe to show menu
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 % 2gives1β not fully divisible β odd.14 % 2gives0β 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
messagevariable equal to"The number is even". - If the number is odd β make the
messagevariable equal to"The number is odd".
Use two different if statements to do this.
The result will be displayed automatically below the function.
Solution
Thanks for your feedback!
single