Lesson 1 of 10
Your first program
- 8 min
- 5 checks
- 3 hints
- Go to task
Goal
Printing with puts and string interpolation
Explanation
Ruby reads almost like everyday speech: there's no semicolon at the end of a line, and you usually don't need parentheses around the values you pass to a method. Everything in Ruby is an object, numbers and strings included, so you can write 5.even? or "Layan".length.
puts prints whatever you give it and then moves to a new line. To put a variable's value inside a string, write it between #{ }, like "Level #{level}". This is called string interpolation, and it converts the number to text for you.
Interpolation only works inside double quotes. Between single quotes, '#{level}' is printed exactly as written, character for character.
Your task
Define name as a string and level as an integer, then print a single line that combines them using interpolation.
Checks
5 checks- name is a non-empty string
- level is an integer
- The name was printed
- The level was printed on the same line as the name
- #{ } is used instead of joining strings