Menu
Coddy logo textTech

Recap - Validation Method

Part of the Fundamentals section of Coddy's Ruby journey — lesson 52 of 88.

challenge icon

Challenge

Easy

Define a method called in_range? that takes three parameters: number, min, and max. The method should return true if the number is within the range (inclusive), and false otherwise.

Read three integers from input:

  1. The number to check
  2. The minimum value of the range
  3. The maximum value of the range

Use your in_range? method to check if the number falls within the given range and print the result.

For example, if the inputs are 15, 10, and 20:

  • 15 is between 10 and 20 (inclusive)

The output should be:

true

If the inputs are 5, 10, and 20, the output should be:

false

If the inputs are 10, 10, and 20, the output should be:

true

Try it yourself

# Read input
number = gets.chomp.to_i
min = gets.chomp.to_i
max = gets.chomp.to_i

# TODO: Define the in_range? method below


# Call the method and print the result
puts in_range?(number, min, max)

All lessons in Fundamentals