Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby

Alphonse Cuccurullo
Alphonse Cuccurullo
2,513 Points

Having trouble converting to symbols.

strings = ["HTML", "CSS", "JavaScript", "Python", "Ruby"]

Add your code below!

symbols = Array.new strings.to_sym.each do |i| if i !=1 symbols.push(i) end end

puts symbols

This pops up "It looks like you didn't add each symbolized string to the symbols array."

The goal is to iterate over the string and convert them to symbols and add them to a seperate array.

1 Answer

Tim Knight
Tim Knight
28,888 Points

Hi Alphonse,

What about something like this:

strings = ["HTML", "CSS", "JavaScript", "Python", "Ruby"]

# Creates a new empty array
symbols = []

strings.each do |string|
  symbols.push(string.to_sym)
end

This converts each item in the string array to a symbol and then adds it to a symbols array. I'm not sure what your intention was with if != 1 but this at least addresses the array of symbols.

You can test it with:

symbols.each do |sym|
  puts sym.class
end

# => Symbol
# => Symbol
# => Symbol
# => Symbol
# => Symbol
# => => [:HTML, :CSS, :JavaScript, :Python, :Ruby]