Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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