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 trialJason Widjaja
7,904 Pointswhat is wrong with my code
idk what is wrong i did the same exact thing for the previous part and got it right
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
food = grocery_item.has_value?("Bread")
1 Answer
Johnathan Guzman
7,432 PointsHey Jason,
For this challenge, we need to add a key and value to the hash - we can do this in two way:
1) using the .store method :
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
if grocery_item.has_value?("Bread")
grocery_item.store("food", true)
end
Or
2) directly add the desired pairs as followed:
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
if grocery_item.has_value?('Bread')
grocery_item["food"] = true
end
I prefer method number 1.
I hope this helps.