Ruby Ruby Collections Ruby Hashes Working with Hash Values

Jennifer Hsueh
Jennifer Hsueh
648 Points

why is task 1 no longer passing?

I haven't changed any of my code for task 1, so why is it not passing now?

hash.rb
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
grocery_item.has_value?("Bread")
grocery_item.store("food", true)
grocery_item.values_at("item")
grocery_list = {"item")

3 Answers

Antonio De Rose
Antonio De Rose
20,866 Points
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
grocery_item.has_value?("Bread") #this line is correct, again it is to check with a condition, so where is "if"
grocery_item.store("food", true) #this line is correct
#in ruby, if you start with if, you should end, it with "end"
grocery_item.values_at("item") #take off this line, question have not asked you to do it
grocery_list = {"item") #take off this line too
Jennifer Hsueh
Jennifer Hsueh
648 Points

sorry, you said: #in ruby, if you start with if, you should end, it with "end" why do i need an if and end here?

and the last 2 lines are for the 2nd task. i've completed it now, but it seems strange to me that the 2nd task asks: "Use the values_at method on the grocery_item hash to get an array consisting of a single value: the value of the "item" key. Store the returned array in a variable named grocery_list."

and i can completely this task using:

grocery_item.values_at("bread") grocery_list = ["Bread"]

OR

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

mazen akkari
mazen akkari
19,696 Points

I also got confused, it's the way the question is asked. Thanks for the help Jennifer

Antonio De Rose
Antonio De Rose
20,866 Points

sure, send me the code, with the screenshot, to see, what you have tried.