Ruby Tutorial – Object Methods

Problem Statement

Each object in Ruby may have methods associated with it. To demonstrate this, we want you to print whether a number is even or odd. A number has an even? method associated with it, which returns true or false based on the parity of the number.

Assuming a variable number is already defined, check whether a given number is even or not.

Hint

Type in the code-editor

return number.even?

or

number.even?

Solution

  
# add your code here
return number.even?


Leave a Reply