Day 23: Playing in the Treehouse

I’m back at the Ruby Learning game, friends. Let’s jump in! I want to get through a lot, so I am going to hustle.

I am on the last stage of the Ruby Collections course, Build a Grocery List Program.

First video is Build a Grocery List Program: Part 1.

Here is the code:

Results:

treehouse:~/workspace$ ruby shopping_list.rb
What is the list name?Groceries
{“name”=>”Groceries”, “items”=>[]}

And the challenge:

Challenge Task 1 of 1

Create a method named “create_shopping_list” that returns a hash. It does not need to ask for a name or get anything from standard input.

On to the next video! Build a Grocery List Program: Part 2

And the results:

treehouse:~/workspace$ ruby shopping_list.rb
What is the list name? Groceries
{“name”=>”Groceries”, “items”=>[]}
What is the item called? Milk
How much? 1
{“name”=>”Groceries”, “items”=>[{“name”=>”Milk”, “quantity”=>1}]}

and the challenge:

Challenge Task 1 of 1

Create a method called add_list_items that returns an array. It does not need to read from standard input.

And the next video: Build a Grocery List Program: Part 3

And the results:

treehouse:~/workspace$ ruby shopping_list.rb
What is the list name? Groceries
{“name”=>”Groceries”, “items”=>[]}
What is the item called? Milk
How much? 2
{“name”=>”Groceries”, “items”=>[{“name”=>”Milk”, “quantity”=>2}]}
List: Groceries
—-
Item: Milk
Quantity: 2

and the challenge:

Challenge Task 1 of 1

Modify the “create_shopping_list” method to return a hash with the following keys and values:
‘title’: A string with the value “Grocery List”
‘items’: An empty array

Just to pause here. I do feel like I am learning a lot in this course. I am actually able to read the challenges and know what to do pretty quickly. Just a thought!

Onward! Build a Grocery List Program: Part 4

The code:

The results:

treehouse:~/workspace$ ruby shopping_list.rb
What is the list name? Groceries
Great! Add some items to your list.
What is the item called? Milk
How much? 1
What is the item called? Bread
How much? 2
What is the item called? Eggs
How much? 3
Here’s your list:
List: Groceries
——————————————————————————–
Item: Milk Quantity: 1
Item: Bread Quantity: 2
Item: Eggs Quantity: 3
——————————————————————————–

The challenge:

Challenge Task 1 of 1

Add the grocery_item hash to the items array inside of the grocery_list hash.

And after the quiz:

ON TO RUBY LOOPS!

First video:

and the result:

treehouse:~/workspace$ ruby loop.rb
Do you want to continue? (y/n) y
Do you want to continue? (y/n) y
Do you want to continue? (y/n) y
Do you want to continue? (y/n) n
treehouse:~/workspace$

The challenge question:

Using the loop construct, add the current value of number to the numbers array. Inside of the loop, add 1 to the number variable. If the numbers array has more than 3 items, use the break keyword to exit the loop.

Well, I’m ending here for tonight. My goals yesterday were pretty lofty. I hope to finish the loops portion tomorrow!