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

christine picone
christine picone
4,510 Points

ruby hashes challenge: task 1 no longer passing

I'm not sure what is going wrong here. I passed task 1, then I get an error message. Does anyone know what could be wrong?

Thanks!

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

#Task 1
grocery_item.has_value?("Bread")

if grocery_item.has_value?("Bread") == true
grocery_item.store("food", true)
end


#Task 2
grocery_list = [ grocery_item.values_at?("item") ]

2 Answers

Hi Christine,

You need to remove square brackets [ ] around the last output. Then all is good.

#GIVEN
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }

#Task 1
grocery_item.has_value?("Bread")

if grocery_item.has_value?("Bread") == true
grocery_item.store("food", true)
end

#Task 2
grocery_list = grocery_item.values_at("item")
christine picone
christine picone
4,510 Points

Thanks Salman! I wish it wasn't so buggy where I thought that something was wrong with the first task's code. It was driving me crazy!

c