Lesson 3 of 15
String Interpolation
String Interpolation
Swift lets you embed values directly inside strings using \(expr):
let name = "Alice"
let age = 30
print("Hello, \(name)! You are \(age) years old.")
// Hello, Alice! You are 30 years old.
Any expression works inside the parentheses:
let a = 3
let b = 4
print("\(a) + \(b) = \(a + b)")
// 3 + 4 = 7
Your Task
Write a function greet that takes a name (String) and an age (Int), and returns the greeting string "Hello, <name>! You are <age> years old." using string interpolation. Then call it and print the result.
JS Transpiler loading...
Loading...
Click "Run" to execute your code.