Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to insert the variable name inside the string using interpolation.
Ruby
name = "Alice" message = "Hello, [1]!" puts message
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes instead of double quotes for interpolation.
Putting the variable name as a string without #{ }.
Using ${} which is not Ruby syntax.
✗ Incorrect
In Ruby, string interpolation uses #{variable} inside double quotes. So "#{name}" inserts the value of name.
2fill in blank
mediumComplete the code to include the result of 5 + 3 inside the string using interpolation.
Ruby
result = "The sum is [1]" puts result
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes which do not interpolate.
Putting the expression as a string without #{ }.
Using ${} which is not Ruby syntax.
✗ Incorrect
Ruby evaluates expressions inside #{ } in double-quoted strings, so "#{5 + 3}" becomes "8".
3fill in blank
hardFix the error in the code to correctly interpolate the variable age inside the string.
Ruby
age = 30 puts "I am [1] years old."
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name without #{ }.
Using single quotes which do not interpolate.
Putting the variable name as a string.
✗ Incorrect
Interpolation requires #{variable} inside double quotes. So #{age} inserts the value of age.
4fill in blank
hardFill both blanks to create a greeting that includes the first_name and last_name variables using interpolation.
Ruby
first_name = "John" last_name = "Doe" greeting = "Hello, [1] [2]!" puts greeting
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names without #{ }.
Using single quotes which do not interpolate.
✗ Incorrect
Use #{variable} inside double quotes to insert variable values. So #{first_name} and #{last_name} insert the names.
5fill in blank
hardFill all three blanks to create a sentence that includes the city, temperature, and unit variables using interpolation.
Ruby
city = "Paris" temperature = 22 unit = "C" weather = "The temperature in [1] is [2]°[3]." puts weather
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names without #{ }.
Using single quotes which do not interpolate.
Using plain variable names without interpolation.
✗ Incorrect
Use #{variable} inside double quotes to insert variable values. So #{city}, #{temperature}, and #{unit} insert the correct values.