Lesson 3 of 15

String Interpolation

String Interpolation

Scala's s"..." strings let you embed values with $name or ${expr}:

val name = "Alice"
val age = 30
println(s"Hello, $name! You are $age years old.")
// Hello, Alice! You are 30 years old.

For arbitrary expressions, use curly braces:

val a = 3
val b = 4
println(s"$a + $b = ${a + b}")
// 3 + 4 = 7

Your Task

Write a function greet that takes a name (String) and an age (Int) and returns a greeting string using string interpolation: "Hello, <name>! You are <age> years old."

JS Transpiler loading...
Loading...
Click "Run" to execute your code.