diff --git a/final_prep/README.md b/final_prep/README.md index 22bfb5154..7ac474794 100644 --- a/final_prep/README.md +++ b/final_prep/README.md @@ -3,13 +3,13 @@ Congrats on making it to the Mod 0 Final Prep! Complete the final exercises belo ### Final Technical Prep -You've learned a ton about some of the core foundations of Javascript! Show us how far you've come by completing the following exercises! You will be using your work from these exercises in your first day of Mod 1! +You've learned a ton about some of the core foundations of Javascript! Show us how far you've come by completing the following exercises! You will be using your work from these exercises in your first day of Mod 1! -- [ ] Complete the [Mod Zero Hero Challenge](./mod_zero_hero.rb) -- [ ] Complete the [Annotation Challenge](./annotations.rb) +- [x] Complete the [Mod Zero Hero Challenge](./mod_zero_hero.rb) +- [x] Complete the [Annotation Challenge](./annotations.rb) ### Refactor Previous Work -You've learned A LOT over the last few weeks as it relates to technical content - chances are, you probably have some code from your previous exercises that is either sloppy, incorrect, poorly named, etc. Before starting Mod 1, we want you to `refactor` your code - which is the process of adjusting or improving your code for readability and accuracy. +You've learned A LOT over the last few weeks as it relates to technical content - chances are, you probably have some code from your previous exercises that is either sloppy, incorrect, poorly named, etc. Before starting Mod 1, we want you to `refactor` your code - which is the process of adjusting or improving your code for readability and accuracy. Some things to consider as you refactor include... - Are my variable names easy to understand/convey the data type they are assigned to? @@ -38,18 +38,18 @@ When you are finished, add screenshots of your calendar so we can provide feedba ### Mentorship Prep Mentorship is an integral part of the Turing experience and will help jumpstart your technical career. In order to get your mentor relationship started on the right foot, please complete the following deliverables: -- [ ] Complete the [Mentorship DTR Prep](https://gist.github.com/ericweissman/51965bdcbf42970d43d817818bfaef3c) - - [ ] Add link to your gist here: +- [x] Complete the [Mentorship DTR Prep](https://gist.github.com/ericweissman/51965bdcbf42970d43d817818bfaef3c) + - [x] Add link to your gist here: [Mentorship gist](https://gist.github.com/Tross0208/d6d5fb2b9f4e41e486d332ae0bcbe615) ### Lesson Prep You've learned a lot about how to take strong notes during Mod 0. Show us your skills while you learn how to pre-teach content for your first lesson in Mod 1! -- [ ] Complete the [Pre Teaching Practice exercise](https://gist.github.com/ericweissman/0036e8fe272c02bd6d4bb14f42fd2f79) gist - - [ ] Add a link to your gist here: +- [x] Complete the [Pre Teaching Practice exercise](https://gist.github.com/ericweissman/0036e8fe272c02bd6d4bb14f42fd2f79) gist + - [x] Add a link to your gist here:[Lesson Prep](https://gist.github.com/Tross0208/509b47cf45a6a57b473f7b2bc60676af) ### Group Work Prep As part of Turing's project-based learning approach, you will often be working in pairs or larger groups. In order to set yourself (and your team) up for success, it is important to ensure you are prepared to be an equitable contributor and teammate. -- [ ] Complete the [DTR Guiding Questions](https://gist.github.com/ericweissman/c56f3a98cdce761808c21d498a52f5c6) - - [ ] Add a link to your gist here: +- [x] Complete the [DTR Guiding Questions](https://gist.github.com/ericweissman/c56f3a98cdce761808c21d498a52f5c6) + - [x] Add a link to your gist here: [Group work](https://gist.github.com/Tross0208/c10e7b42792a5f31a45045d9cc664d73) ## All Done? How to Submit your M1 Prework When you have completed *all* the activities described above, follow the steps below to submit your technical prework. @@ -86,4 +86,4 @@ What is your plan and how are you going to hold yourself to it? Specifically... - What personal items/events are important to you during this time? How are you going to make sure those are not neglected? (Hint, block time on the calendar for them!) ## Extensions -Check out our thoughts on [extension activities](https://mod0.turing.io/prework/extensions) if you find yourself with some extra time before starting Mod 1! \ No newline at end of file +Check out our thoughts on [extension activities](https://mod0.turing.io/prework/extensions) if you find yourself with some extra time before starting Mod 1! diff --git a/final_prep/annotations.rb b/final_prep/annotations.rb index 8b938706c..007c84540 100644 --- a/final_prep/annotations.rb +++ b/final_prep/annotations.rb @@ -4,40 +4,40 @@ # Build a Bear -def build_a_bear(name, age, fur, clothes, special_power) - greeting = "Hey partner! My name is #{name} - will you be my friend?!" - demographics = [name, age] - power_saying = "Did you know that I can #{special_power}?" - built_bear = { - 'basic_info' => demographics, - 'clothes' => clothes, - 'exterior' => fur, - 'cost' => 49.99, - 'sayings' => [greeting, power_saying, "Goodnight my friend!"], - 'is_cuddly' => true, +def build_a_bear(name, age, fur, clothes, special_power) # Method taking in 5 parameters + greeting = "Hey partner! My name is #{name} - will you be my friend?!" #Variable greeting with interpolated name + demographics = [name, age] #Variable demographics set to array of name and age + power_saying = "Did you know that I can #{special_power}?" #Variable power saying set to string with interpolated special power + built_bear = { # Hash with 6 key:value pairs + 'basic_info' => demographics, #Key basic info with value of array variable demographics + 'clothes' => clothes,# Key clothes set to passed value from clothes parameter + 'exterior' => fur,# Key exterior set to passed value from fur parameter + 'cost' => 49.99, #key cost set to value 49.99 + 'sayings' => [greeting, power_saying, "Goodnight my friend!"],#Key sayings with value set to array of variable greeting, variable power saying, and string + 'is_cuddly' => true, #Key is cuddly with value set to boolean } - return built_bear + return built_bear #return hash built bear end -build_a_bear('Fluffy', 4, 'brown', ['pants', 'jorts', 'tanktop'], 'give you nightmares') -build_a_bear('Sleepy', 2, 'purple', ['pajamas', 'sleeping cap'], 'sleeping in') +build_a_bear('Fluffy', 4, 'brown', ['pants', 'jorts', 'tanktop'], 'give you nightmares') #Calls method build a bear +build_a_bear('Sleepy', 2, 'purple', ['pajamas', 'sleeping cap'], 'sleeping in') #Calls method build a bear # FizzBuzz -def fizzbuzz(num_1, num_2, range) - (1..range).each do |i| - if i % num_1 === 0 && i % num_2 === 0 +def fizzbuzz(num_1, num_2, range) #Method fizzbuzz taking in 3 parameters + (1..range).each do |i| #From one to value of parameter range, with counter + if i % num_1 === 0 && i % num_2 === 0 # If counter is evenly divisble into both parameter values output fizzbuzz to console puts 'fizzbuzz' - elsif i % num_1 === 0 + elsif i % num_1 === 0 # If counter is evenly divisble into first paramter value output fizz to console puts 'fizz' - elsif i % num_2 === 0 + elsif i % num_2 === 0 # If counter is evenly divisble into second paramter value output buzz to console puts 'buzz' - else + else #If counter is not evenly divisble into either value, output counter value to console puts i end end end -fizzbuzz(3, 5, 100) -fizzbuzz(5, 8, 400) \ No newline at end of file +fizzbuzz(3, 5, 100) #Call method fizzbuzz with 3 parameters +fizzbuzz(5, 8, 400) #Call method fizzbuzz again with 3 different parameters diff --git a/final_prep/mod_zero_hero.rb b/final_prep/mod_zero_hero.rb index 35eb2cdac..cd4e75cdc 100644 --- a/final_prep/mod_zero_hero.rb +++ b/final_prep/mod_zero_hero.rb @@ -1,40 +1,62 @@ # Challenge - See if you can follow the instructions and complete the exercise in under 30 minutes! # Declare two variables - hero_name AND special_ability - set to strings +hero_name = "Blob" +special_ability = "amorphism" # Declare two variables - greeting AND catchphrase # greeting should be assigned to a string that uses interpolation to include the hero_name # catchphrase should be assigned to a string that uses interpolation to include the special_ability +greeting = "Ahhh what am I?" +catchphrase = "Couldn't I at least be non-newtonian?" + # Declare two variables - power AND energy - set to integers +power = 30 +energy = 2 # Declare two variables - full_power AND full_energy # full_power should multiply your current power by 500 # full_energy should add 150 to your current energy +full_power = power * 500 +full_energy = energy + 150 # Declare two variables - is_human and identity_concealed - assigned to booleans - +is_human = false +identitity_concealed = false # Declare two variables - arch_enemies AND sidekicks # arch_enemies should be an array of at least 3 different enemy strings # sidekicks should be an array of at least 3 different sidekick strings - +arch_enemies = ["Sidewalk Gum", "Photo ID", "Gutters" ] +sidekicks = ["Large Tupperware", "Wheel Barrow", "Hydrophilic Coating" ] # Print the first sidekick to your terminal +puts sidekicks[0] # Print the last arch_enemy to the terminal +puts arch_enemies[2] # Write some code to add a new arch_enemy to the arch_enemies array - +arch_enemies.push "Thirsty Seagull" # Print the arch_enemies array to terminal to ensure you added a new arch_enemey - +puts arch_enemies # Remove the first sidekick from the sidekicks array - +sidekicks.shift # Print the sidekicks array to terminal to ensure you added a new sidekick - +puts sidekicks # Create a function called assess_situation that takes three arguments - danger_level, save_the_day, bad_excuse # - danger_level should be an integer -# - save_the_day should be a string a hero would say once they save the day +# - save_the_day should be a string a hero would say once they save the day # - bad_excuse should be a string a hero would say if they are too afraid of the danger_level +def assess_situation (danger_level, save_the_day, bad_excuse) + if danger_level > 50 + puts bad_excuse + elsif danger_level > 10 && danger_level <=50 + puts save_the_day + else + puts "Meh. Hard pass." + end +end # Your function should include an if/else statement that meets the following criteria # - Danger levels that are above 50 are too scary for your hero. Any danger level that is above 50 should result in printing the bad_excuse to the terminal @@ -47,6 +69,9 @@ # assess_situation(99, announcement, excuse) > Should print - 'I think I forgot to lock up my 1992 Toyota Coralla. Be right back.' #assess_situation(21, announcement, excuse) > should print - 'Never fear, the Courageous Curly Bracket is here!' #assess_situation(3, announcement, excuse) > should print - "Meh. Hard pass." +assess_situation(99, announcement, excuse) +assess_situation(21, announcement, excuse) +assess_situation(3, announcement, excuse) # Declare a new variable - scary_monster - assigned to an hash with the following key/values # - name (string) @@ -55,18 +80,59 @@ # - citiesDestroyed (array) # - luckyNumbers (array) # - address (hash with following key/values: number , street , state, zip) +scary_monster = { + name: "Blarg", + smell: "Copper and Gardenia", + weight: 312, + citiesDestroyed: ["Carmel, IN", "Elizabeth Township, NJ"], + luckyNumbers: [7, 13, 21], + address: { + number: 515, + street: "Walla Walla Way", + state: "Washington", + zip: 12345 + } +} # Create a new class called SuperHero # - Your class should have the following DYNAMIC values -# - name +# - name # - super_power -# - age +# - age # - Your class should have the following STATIC values # - arch_nemesis, assigned to "The Syntax Error" # - power_level = 100 -# - energy_level = 50 - +# - energy_level = 50 +class SuperHero + @@arch_nemesis = "The Syntax Error" + @@power_level = 100 + @@energy_level = 50 + def initialize (name, super_power, age) + @name = name#= "The Sloth" + @super_power = super_power#= "Super slow" + @age = age #= 31 + + end + + def say_name + puts @name + end + + def maximize_energy + @@energy_level = 1000 + end + + def gain_power(power) + @@power_level += power + end +end + +thunder_fingers = SuperHero.new("Thunder Fingers", "Fast typing", 24) +google_master = SuperHero.new("Google Master", "The first google search is always right", 34) + +thunder_fingers.say_name +google_master.say_name # - Create the following class methods # - say_name, should print the hero's name to the terminal # - maximize_energy, should update the energy_level to 1000 @@ -77,8 +143,9 @@ # Reflection # What parts were most difficult about this exerise? - +# Nested hashes took some time to figure out. Static vs dynamic class variables was new as well. # What parts felt most comfortable to you? - +#Syntax is starting to sink in. I don't think I had to look up basic formatting questions here. # What skills do you need to continue to practice before starting Mod 1? - +#I dont have a good grasp of which topics I don't know until I am confronted by a new topic/issue. +#On second thought my vocabulary is poor. I do need to practice that. diff --git a/section1/README.md b/section1/README.md index 4239d2a0c..1d394149e 100644 --- a/section1/README.md +++ b/section1/README.md @@ -139,7 +139,7 @@ This will open the `section1` directory in Atom. You should be able to see the d 1. Next, you will complete several lessons from the Learn Ruby the Hard Way Tutorial. *For ***each*** lesson* ***follow these directions closely***: - 1. Create a file within your `section1` directory that will contain this lesson's work. Verify that you are within the directory by using terminal command `pwd`. If you are not, `cd` into your `section1` directory. Once you are there, use the `touch` command in your terminal to create a file. For the first lesson, name this file `ex1.rb`. For each subsequent lesson, use `ex2.rb`, `ex3.rb`, so on, so forth. + 1. Create a file within your `section1` directory that will contain this lesson's work. Verify that you are within the directory by using terminal command `pwd`. If you are not, `cd` into your `section1` directory. Once you are there, use the `touch` command in your terminal to create a file. For the first lesson, name this file `ex1.rb`. For each subsequent lesson, use `ex2.rb`, `ex3.rb`, so on, so forth. 1. Work through the lesson, **typing** the code into your file, and running it in the terminal with `ruby ex1.rb`, replacing `ex1` with the actual file name of what you'd like to run. Make sure the output you get is similar to what the lesson shows. If you get an error saying "No such file or directory", be sure to verify the directory you are located in via the terminal- running command `ls` should show the file you are trying to run. @@ -149,19 +149,19 @@ This will open the `section1` directory in Atom. You should be able to see the d 1. Check off the items below as you complete the steps you just read for each lesson. ***Remember to create a file containing your work for each lesson!*** - - [ ] [A Good First Program](https://learnrubythehardway.org/book/ex1.html) + - [x] [A Good First Program](https://learnrubythehardway.org/book/ex1.html) - - [ ] [Comments in Code](https://learnrubythehardway.org/book/ex2.html) + - [x] [Comments in Code](https://learnrubythehardway.org/book/ex2.html) - - [ ] [Numbers and Math](https://learnrubythehardway.org/book/ex3.html) + - [x] [Numbers and Math](https://learnrubythehardway.org/book/ex3.html) - - [ ] [Variables and Names](https://learnrubythehardway.org/book/ex4.html) + - [x] [Variables and Names](https://learnrubythehardway.org/book/ex4.html) - - [ ] [Strings](https://learnrubythehardway.org/book/ex5.html) + - [x] [Strings](https://learnrubythehardway.org/book/ex5.html) - - [ ] [More Strings](https://learnrubythehardway.org/book/ex6.html) + - [x] [More Strings](https://learnrubythehardway.org/book/ex6.html) - - [ ] [Asking for Input](https://learnrubythehardway.org/book/ex11.html) + - [x] [Asking for Input](https://learnrubythehardway.org/book/ex11.html) 1. Work through the [Strings](http://tutorials.jumpstartlab.com/projects/ruby_in_100_minutes.html#3.-strings) and [Numbers](http://tutorials.jumpstartlab.com/projects/ruby_in_100_minutes.html#5.-numbers) sections from Ruby in 100 Minutes. For each of these sections, open an `irb` session by typing `irb` into your terminal and type in the code snippets provided. diff --git a/section1/ex1.rb b/section1/ex1.rb new file mode 100644 index 000000000..4bf208ac3 --- /dev/null +++ b/section1/ex1.rb @@ -0,0 +1,7 @@ +puts "Hello World!" +puts "Hello Again" +puts "I like typing this." +puts "This is fun." +puts "Yay! Printing." +puts "I'd much rather you 'not'." +puts 'I "said" do not touch this' diff --git a/section1/ex2.rb b/section1/ex2.rb new file mode 100644 index 000000000..dffb2b27c --- /dev/null +++ b/section1/ex2.rb @@ -0,0 +1,9 @@ +# A comment, this is so you can read your program later. +# Anything after the # is ignored by ruby. + +puts "I could have code like this." # and the comment after is ignored + +# You can also use a comment to "disable" or comment out a piece of code: +# puts "This won't run." + +puts "This will run." diff --git a/section1/ex3.rb b/section1/ex3.rb new file mode 100644 index 000000000..0b7380c60 --- /dev/null +++ b/section1/ex3.rb @@ -0,0 +1,23 @@ +puts "I will now count my chickens:" + +puts "Hens #{25 + 30 / 6}" +puts "Roosters #{100 - 25 * 3 % 4}" + +puts "Now I will count the eggs:" + +puts 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6 + +puts "Is it true that 3 + 2 < 5 - 7?" + +puts 3 + 2 < 5 - 7 + +puts "What is 3 + 2? #{3 + 2}" +puts "What is 5 - 7? #{5 - 7}" + +puts "Oh, that's why it's false." + +puts "How about some more." + +puts "Is it greater? #{5 > -2}" +puts "Is it greater or equal? #{5 >= -2}" +puts "Is it less or equal? #{5 <= -2}" diff --git a/section1/ex4.rb b/section1/ex4.rb new file mode 100644 index 000000000..979127ae3 --- /dev/null +++ b/section1/ex4.rb @@ -0,0 +1,16 @@ +cars = 100 +space_in_a_car = 4.0 +drivers = 30 +passengers = 90 +cars_not_driven = cars - drivers +cars_driven = drivers +carpool_capacity = cars_driven * space_in_a_car +average_passengers_per_car = passengers / cars_driven + + +puts "There are #{cars} cars available." +puts "There are only #{drivers} drivers available." +puts "There will be #{cars_not_driven} empty cars today." +puts "We can transport #{carpool_capacity} people today." +puts "We have #{passengers} to carpool today." +puts "We need to put about #{average_passengers_per_car} in each car." diff --git a/section1/ex5.rb b/section1/ex5.rb new file mode 100644 index 000000000..92459ef47 --- /dev/null +++ b/section1/ex5.rb @@ -0,0 +1,17 @@ +my_name = 'Zed A. Shaw' +my_age = 35 # not a lie in 2009 +my_height = 74 # inches +my_weight = 180 # lbs +my_eyes = 'Blue' +my_teeth = 'White' +my_hair = 'Brown' + +puts "Let's talk about #{my_name}." +puts "He's #{my_height} inches tall." +puts "He's #{my_weight} pounds heavy." +puts "Actually that's not too heavy." +puts "He's got #{my_eyes} eyes and #{my_hair} hair." +puts "His teeth are usually #{my_teeth} depending on the coffee." + +# this line is tricky, try to get it exactly right +puts "If I add #{my_age}, #{my_height}, and #{my_weight} I get #{my_age + my_height + my_weight}." diff --git a/section1/ex6.rb b/section1/ex6.rb new file mode 100644 index 000000000..7df0d653b --- /dev/null +++ b/section1/ex6.rb @@ -0,0 +1,21 @@ +types_of_people = 10 +x = "There are #{types_of_people} types of people." +binary = "binary" +do_not = "don't" +y = "Those who know #{binary} and those who #{do_not}." + +puts x +puts y + +puts "I said: #{x}." +puts "I also said: '#{y}'." + +hilarious = false +joke_evaluation = "Isn't that joke so funny?! #{hilarious}" + +puts joke_evaluation + +w = "This is the left side of..." +e = "a string with a right side." + +puts w + e diff --git a/section1/ex7.rb b/section1/ex7.rb new file mode 100644 index 000000000..4bd3b1902 --- /dev/null +++ b/section1/ex7.rb @@ -0,0 +1,8 @@ +print "How old are you? " +age = gets.chomp +print "How tall are you? " +height = gets.chomp +print "How much do you weigh? " +weight = gets.chomp + +puts "So, you're #{age} old, #{height} tall and #{weight} heavy." diff --git a/section1/exercises/booleans.rb b/section1/exercises/booleans.rb index d3216d9d5..9249a8cbc 100644 --- a/section1/exercises/booleans.rb +++ b/section1/exercises/booleans.rb @@ -9,7 +9,10 @@ p 7 > 2 # YOU DO: log to the console the result of "hello" is equal to "Hello": +p "hello" === "Hello" # YOU DO: log to the console the result of 3 is not equal to 4: +p 3 != 4 # YOU DO: log to the console the result of 4 is less than or equal to 5: +p 4 <= 5 diff --git a/section1/exercises/interpolation.rb b/section1/exercises/interpolation.rb index 2988c5181..b8107b652 100644 --- a/section1/exercises/interpolation.rb +++ b/section1/exercises/interpolation.rb @@ -23,8 +23,13 @@ speedy = "hare" # YOUR CODE HERE - +p "In a predictable result, the #{slow_poke} beat the #{speedy}!" # YOU DO: # Declare three variables, name/content/data type of your choice. Think carefully about what you name the variables. Remember, the goal is to be concise but descriptive (it's a hard balance!) Then, log out ONE sentence that incorporates all THREE variables. +car = "Lotus Emira" +year = 2022 +engine = "supercharged Toyota V6" + +p "In #{year} the #{car} will be released with a limited edition #{engine}." diff --git a/section1/exercises/loops.rb b/section1/exercises/loops.rb index e8e69523e..017636c11 100644 --- a/section1/exercises/loops.rb +++ b/section1/exercises/loops.rb @@ -10,13 +10,17 @@ # Write code that prints the sum of 2 plus 2 seven times: 7.times do - # YOUR CODE HERE + p 2 + 2 end # Write code that prints the phrase 'She sells seashells down by the seashore' # ten times: -# YOUR CODE HERE +10.times do + p "She sells seashells down by the seashore" +end # Write code that prints the result of 5 + 7 a total of 9 timees -# YOUR CODE HERE +9.times do + p 5 + 7 +end diff --git a/section1/exercises/numbers.rb b/section1/exercises/numbers.rb index 91435ffb2..4cc1da8ed 100644 --- a/section1/exercises/numbers.rb +++ b/section1/exercises/numbers.rb @@ -7,10 +7,10 @@ p 2 + 2 # Write code that prints the result of 7 subtracted from 83: -p #YOUR CODE HERE +p 83 - 7 # Write code that prints the result of 6 multiplied by 53: -# YOUR CODE HERE +p 6 * 53 # Write code that prints the result of the modulo of 10 into 54: -# YOUR CODE HERE +p 54 % 10 diff --git a/section1/exercises/strings.rb b/section1/exercises/strings.rb index b514a5a63..34ac900f5 100644 --- a/section1/exercises/strings.rb +++ b/section1/exercises/strings.rb @@ -7,9 +7,10 @@ p "Alan Turing" # Write code that prints `Welcome to Turing!` to the terminal: -p #YOUR CODE HERE +p "Welcome to Turing!" # Write code that prints `99 bottles of pop on the wall...` to the terminal: -# YOUR CODE HERE +p "99 bottles of pop on the wall..." -# Write out code to log one line from your favorite song or movie. \ No newline at end of file +# Write out code to log one line from your favorite song or movie. +p "Shake that Laffy Taffy" diff --git a/section1/exercises/variables.rb b/section1/exercises/variables.rb index d765e886a..1e7696a75 100644 --- a/section1/exercises/variables.rb +++ b/section1/exercises/variables.rb @@ -1,6 +1,6 @@ # In the below exercises, write code that achieves # the desired result. To check your work, run this -# file by entering the following command in your terminal: +# file by entering the following command in your terminal: # `ruby section1/exercises/variables.rb` # Example: Write code that saves your name to a variable and @@ -11,49 +11,57 @@ # Write code that saves the string 'Dobby' to a variable and # prints what that variable holds to the terminal: house_elf = "Dobby" -# YOUR CODE HERE +p house_elf # Write code that saves the string 'Harry Potter must not return to Hogwarts!' # and prints what that variable holds to the terminal: -# YOUR CODE HERE +quote = "Harry Potter must not return to Hogwarts!" # Write code that adds 2 to the `students` variable and # prints the result: students = 22 -# YOUR CODE HERE +students += 2 p students # Write code that subracts 2 from the `students` variable and # prints the result: -# YOUR CODE HERE +students -= 2 p students # YOU DO: -# Declare three variables, named `first_name`, `is_hungry` and `number_of_pets`. +# Declare three variables, named `first_name`, `is_hungry` and `number_of_pets`. # Store the appropriate data types in each. # print all three variables to the terminal. - +first_name = "Tyler" +is_hungry = false +number_of_pets = 0 # IN WORDS: -# How did you decide to use the data type you did for each of the three variables above? - -# Explain. +# How did you decide to use the data type you did for each of the three variables above? +#first_name is a word, is_hungry is a yes or no question, number_of_pets is a numeric value unlikely to be fractional. # YOU DO: # Re-assign the values to the three variables from the previous challenge to different values (but same data type). # print all three variables to the terminal. - +first_name = "Dalton" +is_hungry = true +number_of_pets = 1 +p first_name +p is_hungry +p number_of_pets # YOU DO: # Using the variables below, print the total number of snacks to the terminal: healthy_snacks = 6; junk_food_snacks = 8; +p healthy_snacks + junk_food_snacks + #------------------- # FINAL CHECK #------------------- -# Did you run this file in your terminal to make sure everything printed out to the terminal - # as you would expect? \ No newline at end of file +# Did you run this file in your terminal to make sure everything printed out to the terminal + # as you would expect? Not yet. Now I have. diff --git a/section1/reflection.md b/section1/reflection.md index 7ce0895a6..10b401c73 100644 --- a/section1/reflection.md +++ b/section1/reflection.md @@ -2,18 +2,30 @@ 1. How did the SuperLearner Article resonate with you? What from this list do you already do? Want to start doing or do more of? Is there anything not on this list, that you would add to it? +I read a lot, view learning as a process, have a growth mindset, and take care of my brain. I could be more proactive in trying to teach others, and could take more frequent but shorter breaks. + + 1. How would you print the string `"Hello World!"` to the terminal? +`puts "Hello World!"`` -1. What character is used to indicate comments in a ruby file? +2. What character is used to indicate comments in a ruby file? +`#` -1. Explain the difference between an integer and a float? +3. Explain the difference between an integer and a float? +An integer is a whole number. a float may contain decimals -1. In the space below, create a variable `animal` that holds the string `"zebra"` +4. In the space below, create a variable `animal` that holds the string `"zebra"` +`animal = "zebra"` -1. How would you print the string `"zebra"` using the variable that you created above? +5. How would you print the string `"zebra"` using the variable that you created above? +`puts animal` -1. What is interpolation? Use interpolation to print a sentence using the variable `animal`. +6. What is interpolation? Use interpolation to print a sentence using the variable `animal`. +`puts "A #{zebra} is black and white"` -1. What method is used to get input from a user? +7. What method is used to get input from a user? +`gets` -1. Name and describe two common string methods: \ No newline at end of file +8. Name and describe two common string methods: +`string.length` outputs the number of characters in a string. +`string.[x]` returns the character at position x diff --git a/section1/secret_library_project/README.md b/section1/secret_library_project/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secret_library_project/lib/library_system.rb b/section1/secret_library_project/lib/library_system.rb new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secret_library_project/lib/patron.rb b/section1/secret_library_project/lib/patron.rb new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secret_library_project/lib/secret_book.rb b/section1/secret_library_project/lib/secret_book.rb new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secret_library_project/lib/secret_librarian.rb b/section1/secret_library_project/lib/secret_librarian.rb new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secret_library_project/lib/secret_library.rb b/section1/secret_library_project/lib/secret_library.rb new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secret_library_project/package.rb b/section1/secret_library_project/package.rb new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secret_library_project/test/library_system.rb b/section1/secret_library_project/test/library_system.rb new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secret_library_project/test/patron.rb b/section1/secret_library_project/test/patron.rb new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secret_library_project/test/secret_book.rb b/section1/secret_library_project/test/secret_book.rb new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secret_library_project/test/secret_librarian.rb b/section1/secret_library_project/test/secret_librarian.rb new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secret_library_project/test/secret_library.rb b/section1/secret_library_project/test/secret_library.rb new file mode 100644 index 000000000..e69de29bb diff --git a/section2/README.md b/section2/README.md index b81832248..f3752ab06 100644 --- a/section2/README.md +++ b/section2/README.md @@ -29,7 +29,7 @@ Read the three blog posts that follow: * [Asking better questions](https://dev.to/josefine/asking-better-questions-2e2k) * [Your Questions Are Dumb; Ask Them Anyway](https://dev.to/kathryngrayson/your-questions-are-dumb-ask-them-anyway-3cm6) -Reflect on these posts, and how you feel about asking questions (specifically, technical questions as you enter your technical work at Turing). How might this positively or negatively impact your growth? +Reflect on these posts, and how you feel about asking questions (specifically, technical questions as you enter your technical work at Turing). How might this positively or negatively impact your growth? It's going to take some time to find that balance between googling and pushing yourself to solve a problem without hand-holding, and reaching out for help. That's ok! be patient with yourself. The way you will find that balance is by being cognizant and aware of how you currently operate. Keep this on your mind as you work through this section, and... there is no time like the present to start asking questions! @@ -44,19 +44,19 @@ When you are all done with the lessons, exercises, and questions for today, you ### Open your local copy of backend_mod_1_prework -Using your terminal, open your local copy of the forked repository you created during setup. To do this, you will need to use the terminal command `cd` to enter the directory that holds the repository. Once you are in the correct directory, use the terminal command `atom .` to open the prework repository. +Using your terminal, open your local copy of the forked repository you created during setup. To do this, you will need to use the terminal command `cd` to enter the directory that holds the repository. Once you are in the correct directory, use the terminal command `atom .` to open the prework repository. ### If statement and Conditional Lessons 1. Work through the following lessons. Any files that you create while working can be kept in today's `exercises` directory. - - [ ] [What If?](https://learnrubythehardway.org/book/ex29.html) from Learn Ruby the Hard Way. + - [x] [What If?](https://learnrubythehardway.org/book/ex29.html) from Learn Ruby the Hard Way. - - [ ] [Else and If](https://learnrubythehardway.org/book/ex30.html) from Learn Ruby the Hard Way. + - [x] [Else and If](https://learnrubythehardway.org/book/ex30.html) from Learn Ruby the Hard Way. - - [ ] [Making Decisions](https://learnrubythehardway.org/book/ex31.html) from Learn Ruby the Hard Way. + - [x] [Making Decisions](https://learnrubythehardway.org/book/ex31.html) from Learn Ruby the Hard Way. - - [ ] [Conditionals](http://tutorials.jumpstartlab.com/projects/ruby_in_100_minutes.html#9.-conditionals) from Ruby in 100 Minutes. + - [x] [Conditionals](http://tutorials.jumpstartlab.com/projects/ruby_in_100_minutes.html#9.-conditionals) from Ruby in 100 Minutes. 1. Work through the if_statements.rb file in the section2/exercises directory. @@ -68,13 +68,13 @@ Using your terminal, open your local copy of the forked repository you created d _*Note*: In some of these lessons, the author refers to methods as functions. They are interchangable here, but at Turing, we will be use the word `method`._ - - [ ] [Methods](https://launchschool.com/books/ruby/read/methods) from LaunchSchool. Work up to the `obj.method or method(obj)` header. + - [x] [Methods](https://launchschool.com/books/ruby/read/methods) from LaunchSchool. Work up to the `obj.method or method(obj)` header. - - [ ] [Intro to Methods](https://learnrubythehardway.org/book/ex18.html) from Learn Ruby the Hard Way. + - [x] [Intro to Methods](https://learnrubythehardway.org/book/ex18.html) from Learn Ruby the Hard Way. - - [ ] [Methods and Variables](https://learnrubythehardway.org/book/ex19.html) from Learn Ruby the Hard Way. + - [x] [Methods and Variables](https://learnrubythehardway.org/book/ex19.html) from Learn Ruby the Hard Way. - - [ ] [Methods and Return Values](https://learnrubythehardway.org/book/ex21.html) from Learn Ruby the Hard Way. + - [x] [Methods and Return Values](https://learnrubythehardway.org/book/ex21.html) from Learn Ruby the Hard Way. 1. Work through the methods.rb file in the section2/exercises directory. diff --git a/section2/exercises/ex1.rb b/section2/exercises/ex1.rb new file mode 100644 index 000000000..1bcf231f6 --- /dev/null +++ b/section2/exercises/ex1.rb @@ -0,0 +1,36 @@ +people = 20 +cats = 30 +dogs = 15 + + +if people < cats + puts "Too many cats! The world is doomed!" +end + +if people > cats + puts "Not many cats! The world is saved!" +end + +if people < dogs + puts "The world is drooled on!" +end + +if people > dogs + puts "The world is dry!" +end + + +dogs += 5 + +if people >= dogs + puts "People are greater than or equal to dogs." +end + +if people <= dogs + puts "People are less than or equal to dogs." +end + + +if people == dogs + puts "People are dogs." +end diff --git a/section2/exercises/ex2.rb b/section2/exercises/ex2.rb new file mode 100644 index 000000000..b1dd7fc5f --- /dev/null +++ b/section2/exercises/ex2.rb @@ -0,0 +1,26 @@ +people = 30 +cars = 40 +trucks = 15 + + +if cars > people + puts "We should take the cars." +elsif cars < people + puts "We should not take the cars." +else + puts "We can't decide." +end + +if trucks > cars + puts "That's too many trucks." +elsif trucks < cars + puts "Maybe we could take the trucks." +else + puts "We still can't decide." +end + +if people > trucks + puts "Alright, let's just take the trucks." +else + puts "Fine, let's stay home then." +end diff --git a/section2/exercises/ex3.rb b/section2/exercises/ex3.rb new file mode 100644 index 000000000..1d827036f --- /dev/null +++ b/section2/exercises/ex3.rb @@ -0,0 +1,39 @@ +puts "You enter a dark room with two doors. Do you go through door #1 or door #2?" + +print "> " +door = $stdin.gets.chomp + +if door == "1" #Is door a string? why? + puts "There's a giant bear here eating a cheese cake. What do you do?" + puts "1. Take the cake." + puts "2. Scream at the bear." + + print "> " + bear = $stdin.gets.chomp + + if bear == "1" + puts "The bear eats your face off. Good job!" + elsif bear == "2" + puts "The bear eats your legs off. Good job!" + else + puts "Well, doing %s is probably better. Bear runs away." % bear + end + +elsif door == "2" + puts "You stare into the endless abyss at Cthulhu's retina." + puts "1. Blueberries." + puts "2. Yellow jacket clothespins." + puts "3. Understanding revolvers yelling melodies." + + print "> " + insanity = $stdin.gets.chomp + + if insanity == "1" || insanity == "2" + puts "Your body survives powered by a mind of jello. Good job!" + else + puts "The insanity rots your eyes into a pool of muck. Good job!" + end + +else + puts "You stumble around and fall on a knife and die. Good job!" +end diff --git a/section2/exercises/ex4.rb b/section2/exercises/ex4.rb new file mode 100644 index 000000000..66aefebea --- /dev/null +++ b/section2/exercises/ex4.rb @@ -0,0 +1,16 @@ +def water_status(minutes) + if minutes < 7 + puts "The water is not boiling yet." + elsif minutes == 7 + puts "It's just barely boiling" + elsif minutes == 8 + puts "It's boiling!" + else + puts "Hot! Hot! Hot!" + end +end + +water_status(6) +water_status(7) +water_status(8) +water_status(9) diff --git a/section2/exercises/ex5.rb b/section2/exercises/ex5.rb new file mode 100644 index 000000000..265e6edc0 --- /dev/null +++ b/section2/exercises/ex5.rb @@ -0,0 +1,26 @@ +def say(words = "hello") + puts words + "." +end + +say() +say("hi") +say("how are you") +say("I'm fine") + +a = 5 + +def some_method + a = 3 +end + +puts a + +# Method invocation with a block +[1, 2, 3].each do |num| + puts num +end + +# Method definition +def print_num(num) + puts num +end diff --git a/section2/exercises/ex6.rb b/section2/exercises/ex6.rb new file mode 100644 index 000000000..d14552c2d --- /dev/null +++ b/section2/exercises/ex6.rb @@ -0,0 +1,26 @@ +# this one is like your scripts with ARGV +def print_two(*args) + arg1, arg2 = args + puts "arg1: #{arg1}, arg2: #{arg2}" +end + +# ok, that *args is actually pointless, we can just do this +def print_two_again(arg1, arg2) + puts "arg1: #{arg1}, arg2: #{arg2}" +end + +# this just takes one argument +def print_one(arg1) + puts "arg1: #{arg1}" +end + +# this one takes no arguments +def print_none() + puts "I got nothin'." +end + + +print_two("Zed","Shaw") +print_two_again("Zed","Shaw") +print_one("First!") +print_none() diff --git a/section2/exercises/ex7.rb b/section2/exercises/ex7.rb new file mode 100644 index 000000000..1a7601087 --- /dev/null +++ b/section2/exercises/ex7.rb @@ -0,0 +1,21 @@ +def cheese_and_crackers(cheese_count, boxes_of_crackers) + puts "You have #{cheese_count} cheeses!" + puts "You have #{boxes_of_crackers} boxes of crackers!" + puts "Man that's enough for a party!" + puts "Get a blanket.\n" +end + +puts "We can just give the function numbers directly:" +cheese_and_crackers(20, 30) + +puts "OR, we can use variables from our script:" +amount_of_cheese = 10 +amount_of_crackers = 50 + +cheese_and_crackers(amount_of_cheese, amount_of_crackers) + +puts "We can even do math inside too:" +cheese_and_crackers(10 + 20, 5 + 6) + +puts "And we can combine the two, variables and math:" +cheese_and_crackers(amount_of_cheese + 100, amount_of_crackers + 1000) diff --git a/section2/exercises/ex8.rb b/section2/exercises/ex8.rb new file mode 100644 index 000000000..2a5c9223b --- /dev/null +++ b/section2/exercises/ex8.rb @@ -0,0 +1,36 @@ +def add(a, b) + puts "ADDING #{a} + #{b}" + return a + b +end + +def subtract(a, b) + puts "SUBTRACTING #{a} - #{b}" + return a - b +end + +def multiply(a, b) + puts "MULTIPLYING #{a} * #{b}" + return a * b +end + +def divide(a, b) + puts "DIVIDING #{a} / #{b}" + return a / b +end + +puts "Let's do some math with just functions!" + +age = add(30, 5) #35 +height = subtract(78, 4) #74 +weight = multiply(90, 2) #180 +iq = divide(100, 2) #50 + +puts "Age: #{age}, Height: #{height}, Weight: #{weight}, IQ: #{iq}" + +# A puzzle for the extra credit, type it in anyway. +puts "Here is a puzzle." + +#50/2, 25*180, 74 - 4500, 35 + -4426 +what = add(age, subtract(height, multiply(weight, divide(iq, 2)))) + +puts "That becomes: #{what}. Can you do it by hand?" diff --git a/section2/exercises/if_statements.rb b/section2/exercises/if_statements.rb index f29c45cdd..ec49f64a7 100644 --- a/section2/exercises/if_statements.rb +++ b/section2/exercises/if_statements.rb @@ -3,7 +3,7 @@ # file by entering the following command in your terminal: # `ruby section2/exercises/if_statements.rb` -# Example: Using the weather variable below, write code that decides +# Example: Using the weather variable below, write code that decides # what you should take with you based on the following conditions: # if it is sunny, print "sunscreen" # if it is rainy, print "umbrella" @@ -35,7 +35,7 @@ # Right now, the program will print # out both "I have enough money for a gumball" and -# "I don't have enough money for a gumball". Write a +# "I don't have enough money for a gumball". Write a # conditional statement that prints only one or the other. # Experiment with manipulating the value held within num_quarters @@ -43,13 +43,16 @@ num_quarters = 0 +if num_quarters >= 2 puts "I have enough money for a gumball" +else puts "I don't have enough money for a gumball" +end ##################### # Using the variables defined below, write code that will tell you -# if you have the ingredients to make a pizza. A pizza requires +# if you have the ingredients to make a pizza. A pizza requires # at least two cups of flour and sauce. # You should be able to change the variables to achieve the following outputs: @@ -61,5 +64,11 @@ # Experiment with manipulating the value held within both variables # to make sure all above conditions output what you expect. -cups_of_flour = 1 -has_sauce = true +cups_of_flour = 2 +has_sauce = false + +if cups_of_flour <2 || has_sauce == false + puts "I cannot make pizza" +else + puts "I can make pizza" +end diff --git a/section2/exercises/methods.rb b/section2/exercises/methods.rb index f2517f1b3..ef4b658a0 100644 --- a/section2/exercises/methods.rb +++ b/section2/exercises/methods.rb @@ -12,19 +12,33 @@ def print_name # Write a method that takes a name as an argument and prints it: def print_name(name) - # YOUR CODE HERE + puts name end print_name("Albus Dumbledore") -# Write a method that takes in 2 numbers as arguments and prints +# Write a method that takes in 2 numbers as arguments and prints # their sum. Then call your method three times with different arguments passed in: -# YOUR CODE HERE +def add(num1, num2) + puts num1 +num2 +end + +add(1, 2) +add(4, 20) +add(1.2, 3.4) + +# Write a method that takes in two strings as arguments and prints +# a concatenation of those two strings. Example: The arguments could be +# (man, woman) and the end result might output: "When Harry Met Sally". +# Then call your method three times with different arguments passed in. -# Write a method that takes in two strings as arguments and prints -# a concatenation of those two strings. Example: The arguments could be -# (man, woman) and the end result might output: "When Harry Met Sally". -# Then call your method three times with different arguments passed in. +def fight(blue_corner, red_corner) + puts "#{blue_corner} would totally beat #{red_corner} in a fight" +end + +fight("John Cena", "Nikola Tesla") +fight("Shia LaBeouf", "black olives") +fight("parmesan cheese stink", "Utilitarianism") #------------------- @@ -37,5 +51,5 @@ def print_name(name) # Look at the code you wrote for the previous YOU DO🎈 - what did you name the function, and why? # What did you name each parameter, and why? -# EXPLAIN: - +# EXPLAIN: The function is named fight because it makes the parameters fight each other. +#The parameters are named blue_corner and red_corner because those are their respective starting positions in the ring. diff --git a/section2/reflection.md b/section2/reflection.md index 49f0606df..75231d0a0 100644 --- a/section2/reflection.md +++ b/section2/reflection.md @@ -1,29 +1,56 @@ ## Section 2 Reflection 1. Regarding the blog posts in Part A, how do you feel about asking questions? Do you tend to ask them too soon, or wait too long, or somewhere in between? + I tend to ask too soon with simple questions, and too long with complex questions. ### If Statements 1. What is a conditional statement? Give three examples. - -1. Why might you want to use an if-statement? - -1. What is the Ruby syntax for an if statement? - -1. How do you add multiple conditions to an if statement? - -1. Provide an example of the Ruby syntax for an if/elsif/else statement: - -1. Other than an if-statement, can you think of any other ways we might want to use a conditional statement? + A conditional statement determines the truth of a scenario + +2. Why might you want to use an if-statement? + An if statement is useful when a condition has several different outcomes + +3. What is the Ruby syntax for an if statement? +```ruby +if (variable) (comparator) (variable/value) + outcome +end +``` +4. How do you add multiple conditions to an if statement? +Any number of elsif statements may be added for various outcomes + +5. Provide an example of the Ruby syntax for an if/elsif/else statement: +```ruby +if (variable) (comparator) (variable/value) + outcome +elsif (variable) (comparator) (variable/value) + outcome +else + outcome +end +``` +6. Other than an if-statement, can you think of any other ways we might want to use a conditional statement? +Conditional statements can be used in loops as well. ### Methods 1. In your own words, what is the purpose of a method? - -1. Create a method named `hello` that will print `"Sam I am"`. - -1. Create a method named `hello_someone` that takes an argument of `name` and prints `"#{name} I am"`. - -1. How would you call or execute the method that you created above? - -1. What questions do you have about methods in Ruby? \ No newline at end of file +The purpose of a method is to be able to use a part of a code multiple times without rewriting it each time. + +2. Create a method named `hello` that will print `"Sam I am"`. +```ruby +def hello() + puts "Sam I am" +end +``` +3. Create a method named `hello_someone` that takes an argument of `name` and prints `"#{name} I am"`. +```ruby +def hello_someone(name) + puts "#{name} I am" +end +``` +4. How would you call or execute the method that you created above? +`name ("Tyler")` +5. What questions do you have about methods in Ruby? +None yet, feeling comfortable so far. diff --git a/section3/exercises/arrays.rb b/section3/exercises/arrays.rb index f710c6000..19b70c822 100644 --- a/section3/exercises/arrays.rb +++ b/section3/exercises/arrays.rb @@ -18,47 +18,62 @@ print animals # EXAMPLE: Write code below that will print "Zebra" from the animals array -# YOUR CODE HERE + print animals[0] # YOU DO: Write code below that will print the number of elements in array of # animals from above. +puts animals.length + # YOU DO: Write code that will reassign the last item in the animals # array to "Gorilla" +animals[2] = "Gorilla" +#puts animals[2] # YOU DO: Write code that will add a new animal (type of your choice) to position 3. - +animals[3] = "Otter" +#puts animals[3] # YOU DO: Write code that will print the String "Elephant" in the animals array - +animals[4] = "Elephant" +puts animals[4] #------------------- # PART 2: Foods: Array Methods #------------------- # YOU DO: Declare a variable that will store an an array of at least 4 foods (strings) - +foods = ["Grouper", "Pakora", "Wings", "Mole"] # YOU DO: Write code below that will print the number of elements in the array of # foods from above. - +puts foods.length # YOU DO: Write code below that uses a method to add "broccoli" to the foods array and # print the changed array to verify "broccoli" has been added +foods[4] = "Broccoli" +puts foods # YOU DO: Write code below that removes the last item of food from the foods array and # print the changed array to verify that item has been removed +foods.pop() +print foods - -# YOU DO: Write code to add 3 new foods to the array. +# YOU DO: Write code to add 3 new foods to the array. # There are several ways to do this - choose whichever you'd like! # Then, print the changed array to verify the new items have been added +foods[4] = "Celery" +foods << "Bleu Cheese" +foods.push ("Carrots") +print foods # YOU DO: Remove the food that is in index position 0. +foods.shift +print foods #------------------- # PART 3: Where are Arrays used? @@ -77,11 +92,9 @@ posts = ["image at beach", "holiday party", "adorable puppy", "video of cute baby"]; # YOU DO: Think of a web application you commonly use. Where do you see LISTS utilized, where arrays -# may be storing data? Come up with 3 examples - they could be from different web applications or +# may be storing data? Come up with 3 examples - they could be from different web applications or # all from the same one. -# 1: -# 2: -# 3: - - +# 1:Youtube - Subscriptions +# 2:Youtube - Playlists +# 3:Youtube - Uploads diff --git a/section3/exercises/ex1.rb b/section3/exercises/ex1.rb new file mode 100644 index 000000000..c6b3fd205 --- /dev/null +++ b/section3/exercises/ex1.rb @@ -0,0 +1,34 @@ +the_count = [1, 2, 3, 4, 5] +fruits = ['apples', 'oranges', 'pears', 'apricots'] +change = [1, 'pennies', 2, 'dimes', 3, 'quarters'] + +# this first kind of for-loop goes through a list +# in a more traditional style found in other languages +for number in the_count + puts "This is count #{number}" +end + +# same as above, but in a more Ruby style +# this and the next one are the preferred +# way Ruby for-loops are written +fruits.each do |fruit| + puts "A fruit of type: #{fruit}" +end + +# also we can go through mixed lists too +# note this is yet another style, exactly like above +# but a different syntax (way to write it). +change.each {|i| puts "I got #{i}" } + +# we can also build lists, first start with an empty one +elements = [] + +# then use the range operator to do 0 to 5 counts +(0..5).each do |i| + puts "adding #{i} to the list." + # pushes the i variable on the *end* of the list + elements.push(i) +end + +# now we can print them out too +elements.each {|i| puts "Element was: #{i}" } diff --git a/section3/exercises/ex2.rb b/section3/exercises/ex2.rb new file mode 100644 index 000000000..8ff11ddd7 --- /dev/null +++ b/section3/exercises/ex2.rb @@ -0,0 +1,17 @@ +animals = ['bear', 'ruby', 'peacock', 'kangaroo', 'whale', 'platypus'] + +puts "The animal at 1 is #{animals[1]}" + +puts "The third animal is #{animals[2]}" + +puts "The first animal is #{animals[0]}" + +puts "The animal at 3 is #{animals[3]}" + +puts "The fifth animal is #{animals[4]}" + +puts "The animal at 2 is #{animals[2]}" + +puts "The sixth animal is #{animals[5]}" + +puts "the animal at 4 is #{animals[4]}" diff --git a/section3/exercises/ex3.rb b/section3/exercises/ex3.rb new file mode 100644 index 000000000..12054ed4b --- /dev/null +++ b/section3/exercises/ex3.rb @@ -0,0 +1,67 @@ +# create a mapping of state to abbreviation +states = { + 'Oregon' => 'OR', + 'Florida' => 'FL', + 'California' => 'CA', + 'New York' => 'NY', + 'Michigan' => 'MI' +} + +# create a basic set of states and some cities in them +cities = { + 'CA' => 'San Francisco', + 'MI' => 'Detroit', + 'FL' => 'Jacksonville' +} + +# add some more cities +cities['NY'] = 'New York' +cities['OR'] = 'Portland' + +# puts out some cities +puts '-' * 10 +puts "NY State has: #{cities['NY']}" +puts "OR State has: #{cities['OR']}" + +# puts some states +puts '-' * 10 +puts "Michigan's abbreviation is: #{states['Michigan']}" +puts "Florida's abbreviation is: #{states['Florida']}" + +# do it by using the state then cities dict +puts '-' * 10 +puts "Michigan has: #{cities[states['Michigan']]}" +puts "Florida has: #{cities[states['Florida']]}" + +# puts every state abbreviation +puts '-' * 10 +states.each do |state, abbrev| + puts "#{state} is abbreviated #{abbrev}" +end + +# puts every city in state +puts '-' * 10 +cities.each do |abbrev, city| + puts "#{abbrev} has the city #{city}" +end + +# now do both at the same time +puts '-' * 10 +#puts "THIS ONE!" +states.each do |state, abbrev| + city = cities[abbrev] + puts "#{state} is abbreviated #{abbrev} and has city #{city}" +end + +puts '-' * 10 +# by default ruby says "nil" when something isn't in there +state = states['Texas'] + +if !state + puts "Sorry, no Texas." +end + +# default values using ||= with the nil result +city = cities['TX'] +city ||= 'Does Not Exist' +puts "The city for the state 'TX' is: #{city}" diff --git a/section3/exercises/ex4.rb b/section3/exercises/ex4.rb new file mode 100644 index 000000000..df9c188bc --- /dev/null +++ b/section3/exercises/ex4.rb @@ -0,0 +1,14 @@ +produce = {"apples" => 3, "oranges" => 1, "carrots" => 12} +puts "There are #{produce['oranges']} oranges in the fridge." + +produce["grapes"] = 221 +produce +produce["oranges"] = 6 +produce +produce.keys +produce.values + +puts "There are #{produce['grapes']} grapes in the fridge." + +produce = {apples: 3, oranges: 1, carrots: 12} +puts "There are #{produce[:oranges]} oranges in the fridge." diff --git a/section3/exercises/hashes.rb b/section3/exercises/hashes.rb index 9d368c753..e6084f1ac 100644 --- a/section3/exercises/hashes.rb +++ b/section3/exercises/hashes.rb @@ -1,6 +1,6 @@ # In the below exercises, write code that achieves # the desired result. To check your work, run this -# file by entering the following command in your terminal: +# file by entering the following command in your terminal: # `ruby section3/exercises/hashes.rb` # Example: Write code that prints a hash holding grocery store inventory: @@ -8,25 +8,33 @@ p foods # Write code that prints a hash holding zoo animal inventory: -zoo = #YOUR CODE HERE +zoo = {otters: 20, chipmunks: 1232, stoats: 98} p zoo -# Write code that prints all of the 'keys' of the zoo variable +# Write code that prints all of the 'keys' of the zoo variable # you created above: -# YOUR CODE HERE +zoo.each do |animal, count| + puts animal +end -# Write code that prints all of the 'values' of the zoo variable +# Write code that prints all of the 'values' of the zoo variable # you created above: -# YOUR CODE HERE +zoo.each do |animal, count| + puts count +end -# Write code that prints the value of the first animal of the zoo variable +# Write code that prints the value of the first animal of the zoo variable # you created above: -# YOUR CODE HERE +puts zoo.values[0] -# Write code that adds an animal to the zoo hash. +# Write code that adds an animal to the zoo hash. # Then, print the updated hash: -# YOUR CODE HERE +zoo[:squirrel] = 432 +puts zoo +#zoo.each do |animal, count| +# puts "#{animal} #{count}" +#end #------------------- # Part 2: Email @@ -38,17 +46,18 @@ # Declare a variable that stores hash. Each key should be an attribute of an email and each # value should be some appropriate value for that key. Work to have at least 5 key-value pairs. +email = {sender: "Tyler", receiver: "Joe", subject: "Hey", time: 11.29, reply: false} # Write code that prints your email hash to the terminal. +p email - -# Write code that prints all of the 'keys' of the email hash +# Write code that prints all of the 'keys' of the email hash # you created above: -# YOUR CODE HERE +p email.keys -# Write code that prints all of the 'values' of the email hash +# Write code that prints all of the 'values' of the email hash # you created above: -# YOUR CODE HERE +p email.values #------------------- @@ -64,7 +73,7 @@ # posts = ["image at beach", "holiday party", "adorable puppy", "video of cute baby"]; -# Frankly, that was a very simplified version of the Array the Instagram developers have +# Frankly, that was a very simplified version of the Array the Instagram developers have # written and work with. Still probably slightly simplified as we don't know what their code # actually looks like, but it may look more like this: @@ -76,7 +85,7 @@ 'timestamp' => "4:37 PM August 13, 2019", 'number_likes' => 0, 'comments' => [] - }, + }, { 'image_src' => "./images/holiday-party.png", 'caption' => "What a great holiday party omg", @@ -86,16 +95,26 @@ } ] +puts "posts" puts posts +puts "posts[0]" puts posts[0] -# The code snippet above shows an Array with 2 elements. Each element in an -# Object Literal. Each of those Object Literals has 4 key-value pairs. This may LOOK +# The code snippet above shows an Array with 2 elements. Each element in an +# Object Literal. Each of those Object Literals has 4 key-value pairs. This may LOOK # a bit daunting - it's OK! You don't need to be 100% comfortable with this, but it's # good to have some exposure before going into Mod 1. -# YOU DO: Create an array of at least 3 EMAIL Object Literals, using the same +# YOU DO: Create an array of at least 3 EMAIL Object Literals, using the same # key-value pairs you used in your email Object above. -# Then, log the email Array to the console. \ No newline at end of file +# Then, log the email Array to the console. + +email2 = [ + {sender: "Tyler", receiver: "Joe", subject: "Hey", time: 11.29, reply: false}, + {sender: "Joe", receiver: "Tyler", subject: "Hey", time: 12.47, reply: true}, + {sender: "Tyler", receiver: "Joe", subject: "Hey", time: 13.13, reply: true} +] + +puts email2 diff --git a/section3/reflection.md b/section3/reflection.md index cda726fd3..ba6eed4e3 100644 --- a/section3/reflection.md +++ b/section3/reflection.md @@ -1,17 +1,26 @@ ## Section 3 Reflection 1. What are two points from the Growth Mindset article and/or video that either resonated with you, or were brand new to you? +I have experienced trying to grow outside of my zone of proximal develop, and have learned first hand that it is typically not the best route to develop a skill. -1. In which ways do you currently demonstrate a Growth Mindset? In which ways do you _not_? +2. In which ways do you currently demonstrate a Growth Mindset? In which ways do you _not_? +I currently reflect on my skills, do not stress over mistakes (so long as they do not recur frequently), and actively seek challenges. I do not often set goals, and am slow to seek help. -1. What is a Hash, and how is it different from an Array? +3. What is a Hash, and how is it different from an Array? +A hash is a set of key-value pairs, and differs from an array in that it uses arbitrary objects in place of established data types. -1. In the space below, create a Hash stored to a variable named `pet_store`. This hash should hold an inventory of items and the number of that item that you might find at a pet store. +4. In the space below, create a Hash stored to a variable named `pet_store`. This hash should hold an inventory of items and the number of that item that you might find at a pet store. +`pet_store = {"leashes": 20, "Bags of food": 40, "Puppies": 15}` -1. Given the following `states = {"CO" => "Colorado", "IA" => "Iowa", "OK" => "Oklahoma"}`, how would you access the value `"Iowa"`? +5. Given the following `states = {"CO" => "Colorado", "IA" => "Iowa", "OK" => "Oklahoma"}`, how would you access the value `"Iowa"`? +`states.values[1]` -1. With the same hash above, how would we get all the keys? How about all the values? +6. With the same hash above, how would we get all the keys? How about all the values? +`p states.keys` +`p states.values` -1. What is another example of when we might use a hash? In your example, why is a hash better than an array? +7. What is another example of when we might use a hash? In your example, why is a hash better than an array? +A hash could be used to store student information. This is better than an array because each index position can have a label (key) rather than just a value. -1. What questions do you still have about hashes? +8. What questions do you still have about hashes? +I would like to know if there is an accepted convention when there are multiple ways to write a given operation. diff --git a/section4/README.md b/section4/README.md index 8fc2b4761..e810c95ae 100644 --- a/section4/README.md +++ b/section4/README.md @@ -36,13 +36,13 @@ When you are all done with the lessons, exercises, and questions for today, you 1. Work through the following lessons. Any files that you create while working can be kept in today's `exercises` directory. - - [ ] [What Are Objects](https://launchschool.com/books/oo_ruby/read/the_object_model#whatareobjects) section from LaunchSchool. + - [x] [What Are Objects](https://launchschool.com/books/oo_ruby/read/the_object_model#whatareobjects) section from LaunchSchool. - - [ ] [Classes Define Objects](https://launchschool.com/books/oo_ruby/read/the_object_model#classesdefineobjects) section from LaunchSchool. + - [x] [Classes Define Objects](https://launchschool.com/books/oo_ruby/read/the_object_model#classesdefineobjects) section from LaunchSchool. - - [ ] [Classes and Objects Part 1](https://launchschool.com/books/oo_ruby/read/classes_and_objects_part1) from LaunchSchool. + - [x] [Classes and Objects Part 1](https://launchschool.com/books/oo_ruby/read/classes_and_objects_part1) from LaunchSchool. - - [ ] [Objects, Attributes and Methods](http://tutorials.jumpstartlab.com/projects/ruby_in_100_minutes.html#11.-objects,-attributes,-and-methods) from Ruby in 100 Minutes. + - [x] [Objects, Attributes and Methods](http://tutorials.jumpstartlab.com/projects/ruby_in_100_minutes.html#11.-objects,-attributes,-and-methods) from Ruby in 100 Minutes. 1. Work through the files in the section4/exercises directory. diff --git a/section4/exercises/burrito.rb b/section4/exercises/burrito.rb index 967f68b6c..8cde7afca 100644 --- a/section4/exercises/burrito.rb +++ b/section4/exercises/burrito.rb @@ -1,4 +1,4 @@ -# Add the following methods to this burrito class and +# Add the following methods to this burrito class and # call the methods below the class: # 1. add_topping # 2. remove_topping @@ -11,9 +11,30 @@ def initialize(protein, base, toppings) @base = base @toppings = toppings end + + def add_topping(topping) + toppings.push topping + end + + def remove_topping + toppings.shift() + end + + def change_protein(protein) + @protein = protein + end end dinner = Burrito.new("Beans", "Rice", ["cheese", "salsa", "guacamole"]) p dinner.protein p dinner.base p dinner.toppings + +dinner.add_topping("cilantro") +p dinner.toppings + +dinner.remove_topping +p dinner.toppings + +dinner.change_protein("Chorizo") +p dinner.protein diff --git a/section4/exercises/dog.rb b/section4/exercises/dog.rb index 03221314d..183a4cafd 100644 --- a/section4/exercises/dog.rb +++ b/section4/exercises/dog.rb @@ -1,5 +1,5 @@ # In the dog class below, write a `play` method that makes -# the dog hungry. Call that method below the class, and +# the dog hungry. Call that method below the class, and # print the dog's hunger status. class Dog @@ -19,6 +19,11 @@ def bark def eat @hungry = false end + + def play + @hungry = true + end + end fido = Dog.new("Bernese", "Fido", 4) @@ -28,3 +33,5 @@ def eat p fido.hungry fido.eat p fido.hungry +fido.play +p fido.hungry diff --git a/section4/exercises/ex1.rb b/section4/exercises/ex1.rb new file mode 100644 index 000000000..1c5464440 --- /dev/null +++ b/section4/exercises/ex1.rb @@ -0,0 +1,3 @@ +"hello".class + +"world".class diff --git a/section4/exercises/ex2.rb b/section4/exercises/ex2.rb new file mode 100644 index 000000000..0dae038f2 --- /dev/null +++ b/section4/exercises/ex2.rb @@ -0,0 +1,45 @@ +class GoodDog +end + +sparky = GoodDog.new + + +module Speak + def speak(sound) + puts sound + end +end + +class GoodDog + include Speak +end + +class HumanBeing + include Speak +end + +sparky = GoodDog.new +sparky.speak("Arf!") +bob = HumanBeing.new +bob.speak("Hello!") + + +module Speak + def speak(sound) + puts "#{sound}" + end +end + +class GoodDog + include Speak +end + +class HumanBeing + include Speak +end + +puts "---GoodDog ancestors---" +puts GoodDog.ancestors +puts '' +puts "---HumanBeing ancestors---" +puts HumanBeing.ancestors diff --git a/section4/exercises/ex3-2.rb b/section4/exercises/ex3-2.rb new file mode 100644 index 000000000..3b6429dca --- /dev/null +++ b/section4/exercises/ex3-2.rb @@ -0,0 +1,32 @@ +class GoodDog + attr_accessor :name, :height, :weight + + def initialize(n, h, w) + @name = n + @height = h + @weight = w + end + + def speak + "#{name} says arf!" + end + + def change_info(n, h, w) + self.name = n + self.height = h + self.weight = w + end + + def info + "#{self.name} weighs #{self.weight} and is #{self.height} tall." + end +end + + +sparky = GoodDog.new('Sparky', '12 inches', '10 lbs') +puts sparky.info + +sparky.change_info('Spartacus', '24 inches', '45 lbs') +puts sparky.info + +puts sparky.weight diff --git a/section4/exercises/ex3.rb b/section4/exercises/ex3.rb new file mode 100644 index 000000000..044532ec0 --- /dev/null +++ b/section4/exercises/ex3.rb @@ -0,0 +1,33 @@ +class GoodDog + def initialize(name) + @name = name + end + + def speak + "#{@name} says arf!" + end + + def name + @name + end + + def name=(name) + @name = name + end + +end + +sparky = GoodDog.new("Sparky") +puts sparky.speak +puts sparky.name +sparky.name = "Spartacus" +puts sparky.name + + +fido = GoodDog.new("Fido") +puts fido.speak + + + + +#Want to keep this example, continuing example on ex3-2.rb diff --git a/section4/exercises/ex4.rb b/section4/exercises/ex4.rb new file mode 100644 index 000000000..716fc6785 --- /dev/null +++ b/section4/exercises/ex4.rb @@ -0,0 +1,17 @@ +class Student + attr_accessor :first_name, :last_name, :primary_phone_number + + def introduction(target) + puts "Hi #{target}, I'm #{first_name}!" + end + + def favorite_number + 7 + end + +end + +frank = Student.new +frank.first_name = "Frank" +frank.introduction('Katrina') +puts "Frank's favorite number is #{frank.favorite_number}." diff --git a/section4/exercises/person.rb b/section4/exercises/person.rb index 2c26e9570..1d0d45e80 100644 --- a/section4/exercises/person.rb +++ b/section4/exercises/person.rb @@ -1,5 +1,34 @@ -# Create a person class with at least 2 attributes and 2 behaviors. +# Create a person class with at least 2 attributes and 2 behaviors. # Call all person methods below the class and print results # to the terminal that show the methods in action. -# YOUR CODE HERE +class Person + def initialize (name, age, healthy) + @name = name + @age = age + @healthy = healthy + end + + def birthday + @age += 1 + end + + def age + @age + end + + def poisoned + @healthy = false + end + + def healthy + @healthy + end +end + +tyler = Person.new("Tyler", 31, true) +p tyler +tyler.birthday +puts tyler.age +tyler.poisoned +puts tyler.healthy diff --git a/section4/reflection.md b/section4/reflection.md index 68b044b00..b9f59e297 100644 --- a/section4/reflection.md +++ b/section4/reflection.md @@ -1,22 +1,41 @@ ## Section 4 Reflection 1. How different did your workflow feel this week, considering we asked you to follow the Pomodoro technique? +It felt better in some respects, worse in others. 25 minutes is too small a time for me, as it can take me a while to figure out where I left off. 1. Regarding the work you did around setting intentions in Step 1 of the Pomodoro technique - how did that go? Were you surprised by anything (did you find yourself way more focused than you realized, more distracted that you thought you'd be, estimating times accurately or totally off, etc)? +Setting intentions was effective. The intention was usually a very small task due to the time limit, and made it easy to focus on and track progress. 1. In your own words, what is a Class? +A class is a set of common qualities. 1. What is an attribute of a Class? +An attribute is a piece of data belonging to a class. 1. What is behavior of a Class? +A behavior is an action taken by or done to a class. 1. In the space below, create a Dog class with at least 2 attributes and 2 behaviors: ```rb +class Dinner + def initialize (food, beverage) + @food = food + @beverage = beverage + end + def eat_food + @food = false + end + + def drink_beverage + @beverage = false + end +end ``` 1. How do you create an instance of a class? +`name_of_object = Class.new(attributes)` -1. What questions do you still have about classes in Ruby? \ No newline at end of file +1. What questions do you still have about classes in Ruby?