Ruby Ruby Collections Ruby Hashes Working with Hash Values

Anthony Smith
Anthony Smith
2,738 Points

Single Value Array Issue

When I attempt the 2nd task of the challenge (creating a single value array) I seem to undo the task for the first challenge. How is adding an array undoing it if I am not touching the code? Sometimes I can modify it to where it then tells me that my value is not found in the array.

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

grocery_item.has_value?("Bread") 

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

1 Answer

Only item should be in quotes! So it should look like this grocery_list = [grocery_item.values_at("item")]

Kepa Tairua
Kepa Tairua
Pro Student 4,404 Points

Just in addition to the above, your code:

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

is basically saying: grocery_list is an array with one string, and that string is "grocery_item.values_at("

After that, Ruby gets confused because you haven't added a comma or closed square brace when it was expecting one after your string.