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

What's my error here with the values_at method, while applying it to a Ruby Hash in a Code Challenge ?

I am trying to complete, Task 2 of 2 of the Hashes Section.


The task is as follows: Challenge Task 2 of 2

Using the values_at method, create an array called grocery_list with the value of the grocery_item hash at the "item" key.


My answer is : grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }

if [ grocery_item.has_value?("Bread") ] grocery_item["food"] = true end

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


...and I keep getting the error " Task 1 is no longer passing .

I have successfully completed task 1 ( which is the if .... end code, above) and and have added just the last line above for Task 2 that results in the said error.

Am I doing something wrong ? Thank you very much, TTH Community ! Sachin MAINKAR

2 Answers

Here's what I think is happening,

if this is copied from your code

[ grocery_item.has_value?("Bread") ]

it would fail

If you consult the ruby documentation for "control expressions" you will find that ruby doesn't need brackets (or parenthesis) for that matter.

Mr. Parham, Thank you very much for the quick response. However, that task is complete. I am getting an error with the next task ( Task 2) that is simply the one line of code below:

Here's the task: Using the values_at method, create an array called grocery_list with the value of the grocery_item hash at the "item" key.

Here's my answer that is failing: grocery_list[ ] = grocery_item.values_at("item")

Thank you again and regards, Sachin MAINKAR