Menu
Coddy logo textTech

Recap - Product Array

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

challenge icon

Challenge

Easy

Read a single line of input containing comma-separated integers (e.g., 3,5,2,4).

Split the input into an array of integers, then calculate the product of all elements by multiplying them together using a loop. Print the final product.

Remember to start your product variable at 1, not 0.

For example, if the input is 3,5,2,4, the output should be:

120

If the input is 2,3,4, the output should be:

24

If the input is 1,2,3,4,5, the output should be:

120

If the input is 10,5, the output should be:

50

Try it yourself

# Read the comma-separated input
input = gets.chomp

# Split the input into an array of integers
numbers = input.split(",").map(&:to_i)

# Initialize the product variable
product = 1

# TODO: Write your code below to calculate the product of all elements


# Output the result
puts product

All lessons in Fundamentals