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 Ruby Collections Ruby Hashes Working with Hash Values

Anthony Smith
Anthony Smith
2,738 Points

Single Value Array Issue

When I attempt the 2nd task of the challenge (creating a single value array) I seem to undo the task for the first challenge. How is adding an array undoing it if I am not touching the code? Sometimes I can modify it to where it then tells me that my value is not found in the array.

hash.rb
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company", "food" => true }

grocery_item.has_value?("Bread") 

grocery_list = ["grocery_item.values_at("item")"]

1 Answer

Only item should be in quotes! So it should look like this grocery_list = [grocery_item.values_at("item")]

Kepa Tairua
Kepa Tairua
Courses Plus Student 4,404 Points

Just in addition to the above, your code:

grocery_list = ["grocery_item.values_at("item")"]

is basically saying: grocery_list is an array with one string, and that string is "grocery_item.values_at("

After that, Ruby gets confused because you haven't added a comma or closed square brace when it was expecting one after your string.