Menu
Coddy logo textTech

Output with puts

Part of the Fundamentals section of Coddy's Ruby journey — lesson 26 of 88.

You've been using puts throughout this course to display messages. Now let's take a closer look at how it actually works.

The puts method (short for "put string") outputs text to the screen and automatically adds a new line at the end:

puts "Hello"
puts "World"

This outputs:

Hello
World

Each puts statement starts on a new line because of that automatic line break. You can also output multiple items at once by separating them with commas:

puts "Apple", "Banana", "Cherry"

This outputs each item on its own line:

Apple
Banana
Cherry

The puts method is the most common way to display output in Ruby because it keeps your output clean and readable with automatic line breaks.

challenge icon

Challenge

Easy

Use puts to display the following information about a bookstore, with each item on its own line:

  1. Print Welcome to Ruby Books!
  2. Print the three book genres Fiction, Mystery, and Science using a single puts statement with multiple items separated by commas
  3. Print Happy Reading!

Your output should have exactly 5 lines total.

Cheat sheet

The puts method (short for "put string") outputs text to the screen and automatically adds a new line at the end:

puts "Hello"
puts "World"

Output:

Hello
World

You can output multiple items at once by separating them with commas, each on its own line:

puts "Apple", "Banana", "Cherry"

Output:

Apple
Banana
Cherry

Try it yourself

# TODO: Write your code below
# Use puts to display the bookstore information
# Remember: puts with multiple items separated by commas prints each on its own line
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals