Build a Method That Can Identify Odd or Even Numbers in Ruby
In this guide, you will learn how to implement a method that can determine if a number is odd or even.
Guide Tasks
  • Read Tutorial
  • Complete the Exercise

Summary

Build a method that can identify whether a number(s) is odd or even.

Exercise Description

Define a method that, when expecting an even number, will return true if an even number is passed to it and will return false if an odd number is passed to it. The method should also be able to return true/false when expecting odd numbers.

Example Data

> Even?
10 -> true
0 -> true
74834 -> true

1 -> false
101 -> false
74835 -> false

> Odd?
11 -> true
77 -> true
74833 -> true

0 -> false
404 -> false
4838 -> false

Real World Usage

This coding exercise breaks down and helps you understand how to implement a method that can, first, recognize if you are looking for a odd or an even number and second, will tell you whether a certain number(s) is, in fact, an odd or an even number.

Test Cases

Code File