Recap - Validation Method
Part of the Fundamentals section of Coddy's Ruby journey — lesson 52 of 88.
Challenge
EasyDefine 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:
- The number to check
- The minimum value of the range
- 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:
trueIf the inputs are 5, 10, and 20, the output should be:
falseIf the inputs are 10, 10, and 20, the output should be:
trueTry 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
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 42Variables and Data Types
Numbers and VariablesString Data TypeBoolean Data TypeSymbol Data TypeChecking Data TypesNaming ConventionsRecap - Variable Creation8Loops
For Loop with RangesWhile LoopBreakNextRecap - FactorialTimes LoopUntil LoopNested LoopsRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators6Basic IO
Output with putsOutput with print and pOutput With VariablesInput with getsChomp MethodType ConversionRecap - Age CalculatorRecap - True or False9Methods
Defining a MethodMethod ParametersReturn ValuesRecap - Sigma MethodRecap - Validation MethodDefault Parameter Values