Created
March 2, 2020 02:32
-
-
Save harrisonmalone/6c07cbe68af0acb1d754208fc83a24fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # require 'pry-byebug' | |
| # => one piece of ruby value | |
| # strings | |
| # integers | |
| # floats | |
| # booleans | |
| # nil | |
| # => storing multiple pieces of ruby value | |
| # array | |
| # indexes are used to extract one value out of an array | |
| # shopping_items = [ | |
| # "bread", | |
| # "milk", | |
| # "bananas", | |
| # "plums", | |
| # "lettuce" | |
| # ] | |
| # # -5 -4 -3 -2 -1 <--> 0 1 2 3 4 | |
| # p shopping_items | |
| # puts "what do you want you remove from the list?" | |
| # user_selection = gets.chomp | |
| # shopping_items.delete(user_selection) | |
| # p shopping_items | |
| # shopping_items.shift() | |
| # p shopping_items | |
| # puts "what do you want to add to the shopping items?" | |
| # print "> " | |
| # grocery_item = gets.chomp | |
| # shopping_items << grocery_item | |
| # p shopping_items | |
| # puts "which item would you like?" | |
| # puts "" | |
| # puts "1. bread" | |
| # puts "2. milk" | |
| # puts "3. bananas" | |
| # puts "4. plums" | |
| # puts "5. lettuce" | |
| # user_selection = gets.chomp.to_i -1 | |
| # => 2 | |
| # 1. indexes start at 0 | |
| # 2. the bracket notation to access a value in an array | |
| # while 1 == 1 | |
| # # do something | |
| # puts "hello world" | |
| # end | |
| # jar_size = 12 | |
| # jar_full = false | |
| # cups_added = 0 | |
| # while jar_full == false | |
| # cups_added = cups_added + 1 | |
| # puts "Added #{cups_added} cup(s) of water" | |
| # binding.pry | |
| # # 12 >= 12 | |
| # if cups_added >= jar_size | |
| # jar_full = true | |
| # end | |
| # end | |
| # puts "The jar is full" | |
| # while # (some sort of condition) | |
| # end | |
| # shopping_items = [ | |
| # "bread", | |
| # "milk", | |
| # "bananas", | |
| # "plums", | |
| # "lettuce" | |
| # ] | |
| # index = 0 | |
| # while index < shopping_items.length | |
| # puts shopping_items[index] | |
| # # add an incrementor | |
| # index += 1 | |
| # # index = 4 | |
| # end | |
| # 1. while loops | |
| # 2. for in loop | |
| # 3. array method .each (my preferred way of looping through an array) | |
| # shopping_items = [ | |
| # "bread", | |
| # "milk", | |
| # "bananas", | |
| # "plums", | |
| # "lettuce" | |
| # ] | |
| # index = 0 | |
| # for shopping_item in shopping_items | |
| # puts shopping_item | |
| # end | |
| shopping_items = [ | |
| "bread", | |
| "milk", | |
| "bananas", | |
| "plums", | |
| "lettuce" | |
| ] | |
| # name = "harrison" | |
| # def my_method(shopping_items) | |
| # arr = [1,2,3] | |
| # shopping_items.each_with_index do |x, y| | |
| # puts "item #{y + 1} is #{x}" | |
| # name = "harrison" | |
| # end | |
| # end | |
| # my_method(shopping_items) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment