Menu
Coddy logo textTech

Recap - Till 120

Part of the Fundamentals section of Coddy's Swift journey — lesson 35 of 86.

challenge icon

Challenge

Easy

Read a person's current age as input and calculate how many years remain until they turn 120.

You will receive the following input:

  • A single line containing the person's current age as a string (e.g., "25")

Use readLine() to read the input, safely unwrap it with if let, and convert it to an Int. Then calculate the difference between 120 and the current age.

Print: The number of years until the person turns 120

Try it yourself

// Read the person's current age as input
let input = readLine()

// TODO: Write your code below
// 1. Safely unwrap the input using if let
// 2. Convert the string to an Int
// 3. Calculate years remaining until age 120
// 4. Print the result

All lessons in Fundamentals