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 trialmustafa attaie
8,068 Pointsstuck on a challenge task on Arrays
I'm stuck on the 2nd part of the challenge task. Stuck and kinda lost on what is the right approach. I would love it if you could explain what i did wrong a why.
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
grocery_item.has_value?("Bread")
grocery_item["food"] = true
grocery_list.values_at(grocery_item) = "item"
1 Answer
Steve Hunter
57,712 PointsHi Mustafa,
You're nearly there.
The first part is straightforward enough. if the has_value?
method returns true, add to the hash:
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
grocery_item["food"] = true if grocery_item.has_value?("Bread")
Next you want to assign the value associated with "item
" to a variable called grocery_list
. Call the values_at
method on grocery_item
and pass the parameter "item
" - assign the result to grocery_list
.
grocery_list = grocery_item.values_at("item")
I hope that helps,
Steve.