Search⌘ K
AI Features

Exercise 3: Even or Odd?

Explore how to identify even or odd integers using Ruby's Numeric class. This lesson guides you through coding a function that returns 0 for even numbers and 1 for odd numbers, helping you strengthen your understanding of numeric operations in Ruby.

We'll cover the following...

Problem statement

Given an integer, determine if that number is even or not. If the number is even, return 0. Otherwise, return 1.

Example

num = 5
result = 1

num = 2
result = 0

Try it yourself

Ruby
def even_or_odd(num)
result = -99
# Start your code here
return result
end