Menu
Coddy logo textTech

Recap - Age Calculator

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

challenge icon

Challenge

Easy

Read two inputs from the user:

  1. A birth year (integer)
  2. 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 old

Where X is the calculated age.

For example, if the inputs are 1995 and 2024, the output should be:

You are 29 years old

Try 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 interpolation

All lessons in Fundamentals