Recap - Age Calculator
Part of the Fundamentals section of Coddy's Ruby journey — lesson 32 of 88.
Challenge
EasyRead two inputs from the user:
- A birth year (integer)
- The current year (integer)
Calculate the person's age by subtracting the birth year from the current year. Then output the result using string interpolation in the following format:
You are X years oldWhere X is the calculated age.
For example, if the inputs are 1995 and 2024, the output should be:
You are 29 years oldTry it yourself
# Read input
birth_year = gets.chomp.to_i
current_year = gets.chomp.to_i
# TODO: Write your code below to calculate the age
# TODO: Output the result using string interpolationAll 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 False