Lesson 1 of 10

Your first program

Goal

Printing with puts and string interpolation

01

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.

02

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
  1. name is a non-empty string
  2. level is an integer
  3. The name was printed
  4. The level was printed on the same line as the name
  5. #{ } is used instead of joining strings
main.rb
OutputRuby 3.4 (ruby.wasm)

Loading Ruby (about 8 MB). This only happens once. Your browser keeps it after that.

–/5

Checks start once the environment is ready.

5 checks listed under “Your task”.