diff --git a/final_prep/README.md b/final_prep/README.md index 22bfb5154..bb38590ff 100644 --- a/final_prep/README.md +++ b/final_prep/README.md @@ -5,8 +5,8 @@ Congrats on making it to the Mod 0 Final Prep! Complete the final exercises belo 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. @@ -19,37 +19,39 @@ Some things to consider as you refactor include... Take your time as you go back and refactor your exercises from each section. We've included a handy checklist for you to go through below. -- [ ] I have refactored my `section1` exercises to the best of my ability -- [ ] I have refactored my `section2` exercises to the best of my ability -- [ ] I have refactored my `section3` exercises to the best of my ability -- [ ] I have refactored my `section4` exercises to the best of my ability +- [x] I have refactored my `section1` exercises to the best of my ability +- [x] I have refactored my `section2` exercises to the best of my ability +- [x] I have refactored my `section3` exercises to the best of my ability +- [x] I have refactored my `section4` exercises to the best of my ability ### Time Management Prep In Mod 0 you've learned about different techniques for managing your time at Turing. Please create a calendar for your **first 3 weeks of Mod 1**. Feel free to make your calendar fit your style, but we suggest that your calendar should include the following: -- [ ] Standard M1 class schedule (see M1 calendar [here](https://backend.turing.io/module1/) -- [ ] Study/Project work time -- [ ] Health + Wellness +- [x] Standard M1 class schedule (see M1 calendar [here](https://backend.turing.io/module1/)) +- [x] Study/Project work time +- [x] Health + Wellness When you are finished, add screenshots of your calendar so we can provide feedback if needed! -- `Add Week 1 Screenshot Here` -- `Add Week 2 Screenshot Here` -- `Add Week 3 Screenshot Here` +- ![Mod1 Week 1](https://user-images.githubusercontent.com/93220002/140846442-6bf03a22-0225-47d2-be0a-f81507144b09.png) + +- ![Mod1 Week 2](https://user-images.githubusercontent.com/93220002/140846479-734bed23-2a4b-4376-9964-59878ccd0130.png) + +- ![Screen Shot 2021-11-08 at 6 44 48 PM](https://user-images.githubusercontent.com/93220002/140846496-a81e6ca3-3173-4c1b-a29c-4000e6fb028f.png) ### 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: [JD Mentorship DTR Prep](https://gist.github.com/josephdowns/627f4ab499485f0b92601bcfe4a3b5ba) ### 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: [JD Pre Teachning Practice](https://gist.github.com/josephdowns/85b342ec7d76cb8d8027bd1d88833b10) ### 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: [JD DTR Guiding Questions](https://gist.github.com/josephdowns/1ada1c98a66a0f3410eab97cad4beacd) ## 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 +88,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..a65c13a85 100644 --- a/final_prep/annotations.rb +++ b/final_prep/annotations.rb @@ -4,10 +4,17 @@ # Build a Bear +# create a method build_a_bear with arguments name, age, fur, clothes, and special_power def build_a_bear(name, age, fur, clothes, special_power) +# define variable greeting with interpolation to inclue name greeting = "Hey partner! My name is #{name} - will you be my friend?!" +# define variable demographics with an array containing name and age demographics = [name, age] +# define variable power_saying with interpolation to inclued special_power power_saying = "Did you know that I can #{special_power}?" +# define variable built_bear with hash with the following keys/values basic_info/ variable demographics, +# clothes/argument clothes, exterior/ argument fur, cost/49.99, saying/[array greeting, power_saying, "Goodnight +# my friend"], and is_cuddly/boolean true built_bear = { 'basic_info' => demographics, 'clothes' => clothes, @@ -16,23 +23,35 @@ def build_a_bear(name, age, fur, clothes, special_power) 'sayings' => [greeting, power_saying, "Goodnight my friend!"], 'is_cuddly' => true, } + # returns the value of built_bear return built_bear + # end to the method build_a_bear end - +# calling build_a_bear name = "Fluffy", age = 4, fur = "brown", clothes = ["pants", +# "jorts", "tanktop"], special_power = "give you nightmares" build_a_bear('Fluffy', 4, 'brown', ['pants', 'jorts', 'tanktop'], 'give you nightmares') +# calling build_a_bear name = "Sleepy", age = 2, fur = "purple", clothes = ["pajamas", +# "sleeping cap"], special_power = "sleeping in" build_a_bear('Sleepy', 2, 'purple', ['pajamas', 'sleeping cap'], 'sleeping in') # FizzBuzz - +# define method fizzbuzz with argument num_1, num_2, and range def fizzbuzz(num_1, num_2, range) +# using the range function and the loop function, the method fizzbuzz will evaluate each number +# starting with '1' and continuing until the given integer. Setting 'i' as the argument (1..range).each do |i| +# starting an if...else statement if the evauluated number modulo of argument num_1 +# AND num_2 is equal to 0 then put 'fizzbuzz' if i % num_1 === 0 && i % num_2 === 0 puts 'fizzbuzz' +# if the evauluated number modulo of argument num_1 is equal to 0 put 'fizz' elsif i % num_1 === 0 puts 'fizz' +# if the evauluated number modulo of argument num_2 is equal to 0 put 'buzz' elsif i % num_2 === 0 puts 'buzz' +# if none of the above statements are true put 'i' or the current number of the loop else puts i end @@ -40,4 +59,4 @@ def fizzbuzz(num_1, num_2, range) end fizzbuzz(3, 5, 100) -fizzbuzz(5, 8, 400) \ No newline at end of file +fizzbuzz(5, 8, 400) diff --git a/final_prep/mod_zero_hero.rb b/final_prep/mod_zero_hero.rb index 35eb2cdac..5aec0fcb1 100644 --- a/final_prep/mod_zero_hero.rb +++ b/final_prep/mod_zero_hero.rb @@ -2,38 +2,69 @@ # Declare two variables - hero_name AND special_ability - set to strings +hero_name = "Silver Wolf" +special_ability = "telekinesis" + # 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 = "Hello! The name is #{hero_name}!" +catchphrase = "I'll use my #{special_ability} without delay!" + # Declare two variables - power AND energy - set to integers +power = 83 +energy = 76 + # 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 +identity_concealed = true # 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 = ["Argent Spectere", "Grey Ghost", "Commander Blanc"] +sidekicks = ["Cubby", "Black Bear", "Red Fox"] + # Print the first sidekick to your terminal +print sidekicks.first + # Print the last arch_enemy to the terminal +print arch_enemies.last + # Write some code to add a new arch_enemy to the arch_enemies array +arch_enemies << "Wistful Witch" + # Print the arch_enemies array to terminal to ensure you added a new arch_enemey +print 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 +sidekicks << "Kid Wolf" +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 # Your function should include an if/else statement that meets the following criteria @@ -41,6 +72,26 @@ # - Anything danger_level that is between 10 and 50 should result in printing the save_the_day string to the terminal # - If the danger_level is below 10, it means it is not worth your time and should result in printing the string "Meh. Hard pass." to the terminal. +def assess_situation(danger_level, save_the_day, bad_excuse) + + if danger_level < 10 + puts "Meh. Hard pass." + elsif danger_level > 10 && danger_level < 50 + puts save_the_day + else + puts bad_excuse + end +end + +save_the_day = "Silver Wolf will make it right!" +bad_excuse = "I think I hear my kettle whistling. BRB." + + +assess_situation(99, save_the_day, bad_excuse) +assess_situation(21, save_the_day, bad_excuse) +assess_situation(3, save_the_day, bad_excuse) + + #Test Cases announcement = 'Never fear, the Courageous Curly Bracket is here!' excuse = 'I think I forgot to lock up my 1992 Toyota Coralla. Be right back.' @@ -56,29 +107,79 @@ # - luckyNumbers (array) # - address (hash with following key/values: number , street , state, zip) +scary_monster = { + name: "Towering Spider", + smell: "rotten tomatoes", + weight: 2000, + citiesDestroyed: ["Stockholm", "Cairo", "Cancun"], + luckyNumbers: [4, 17, 2520], + address: {number: "4222", street: "Wagontrail", state: "CO", zip: "80014"} +} + # 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 # - 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 # - gain_power, should take an argument of a number and INCREASE the power_level by that number + class SuperHero + attr_reader :name, :super_power, :age + + def initialize(name, super_power, age) + @name = name + @super_power = super_power + @age = age + end + + @arch_nemesis = "The Syntax Error" + @power_level = 100 + @energry_level = 50 + + def say_name + puts name + end + + def maximize_energy + energy_level = 1000 + end + + def gain_power(increase) + power_level + increase + end +end + # - Create 2 instances of your SuperHero class +superhero1 = SuperHero.new("Lucy Goose", "telepathy", 26) +superhero1.say_name + +superhero2 = SuperHero.new("Octavian", "super strength", 47) +superhero2.say_name # Reflection # What parts were most difficult about this exerise? +# The part I struggled with most was the assess_situation function. And that was mostly +# due to me not reading the directions close enough. I had created the function +# a certain way but then looking at the test cases, my function would not work. Re-reading +# the directions told me what I should do. + # What parts felt most comfortable to you? +# I felt most comfortable with the different types of variables. Maybe because we +# use variables in most other things so it has become fundamental to me. + # What skills do you need to continue to practice before starting Mod 1? +# I still need to work on objects and classes. I feel a little better about them +# but I could still use more practice. diff --git a/section1/README.md b/section1/README.md index 4239d2a0c..41893448f 100644 --- a/section1/README.md +++ b/section1/README.md @@ -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/exercises/booleans.rb b/section1/exercises/booleans.rb index d3216d9d5..4ceb8a5da 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": +puts "hello" == "Hello" # YOU DO: log to the console the result of 3 is not equal to 4: +puts 3 != 4 # YOU DO: log to the console the result of 4 is less than or equal to 5: +puts 4 <= 5 diff --git a/section1/exercises/ex1.rb b/section1/exercises/ex1.rb new file mode 100644 index 000000000..7c571d618 --- /dev/null +++ b/section1/exercises/ex1.rb @@ -0,0 +1,8 @@ +#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.' +#puts "Here is another line." diff --git a/section1/exercises/ex11.rb b/section1/exercises/ex11.rb new file mode 100644 index 000000000..f22edd7f8 --- /dev/null +++ b/section1/exercises/ex11.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/ex2.rb b/section1/exercises/ex2.rb new file mode 100644 index 000000000..dffb2b27c --- /dev/null +++ b/section1/exercises/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/exercises/ex3.rb b/section1/exercises/ex3.rb new file mode 100644 index 000000000..64ec8a201 --- /dev/null +++ b/section1/exercises/ex3.rb @@ -0,0 +1,23 @@ +puts "I will now count my chickens:" + +puts "Hens #{25.0 + 30 / 6}" +puts "Roosters #{100.0 - 25 * 3 % 4}" + +puts "Now I will count the eggs:" + +puts 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6.0 + +puts "Is it true that 3 + 2 < 5 - 7?" + +puts 3 + 2 < 5 - 7.0 + +puts "What is 3 + 2? #{3.0 + 2}" +puts "What is 5 - 7? #{5.0 - 7}" + +puts "Oh, that's why it's false." + +puts "How about some more." + +puts "Is it greater? #{5.0 > -2}" +puts "Is it greater or equal? #{5.0 >= -2}" +puts "Is it less or equal? #{5.0 <= -2}" diff --git a/section1/exercises/ex4.rb b/section1/exercises/ex4.rb new file mode 100644 index 000000000..0794bd9c3 --- /dev/null +++ b/section1/exercises/ex4.rb @@ -0,0 +1,22 @@ +#define cars +cars = 100 +#define space_in_a_car +space_in_a_car = 4.0 +#define drivers +drivers = 30 +#define passengers +passengers = 90 +#cars minus drivers 100 - 30 +cars_not_driven = cars - drivers +cars_driven = drivers +#multiply cars_driven by space_in_a_car +carpool_capacity = cars_driven * space_in_a_car +#divide passengers by cars_driven +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/exercises/ex5.rb b/section1/exercises/ex5.rb new file mode 100644 index 000000000..0074714de --- /dev/null +++ b/section1/exercises/ex5.rb @@ -0,0 +1,19 @@ +name = 'Zed A. Shaw' +age = 35 +height = 74 +weight = 180 +eyes = 'Blue' +teeth = 'White' +hair = 'Brown' +cm = height * 2.54 +kg = weight / 2.2 + +puts "Let's talk about #{name}." +puts "He's #{height} inches tall." +puts "He's #{weight} pounds heavy." +puts "Actually that's not too heavy." +puts "He's got #{eyes} eyes and #{hair} hair." +puts "His teeth are usually #{teeth} depending on the coffee." +puts "He is #{cm} centimeters tall and weighs #{kg} kilograms." + +puts "If I add #{age}, #{height}, and #{weight} I get #{age + height + weight}." diff --git a/section1/exercises/ex6.rb b/section1/exercises/ex6.rb new file mode 100644 index 000000000..8a578574c --- /dev/null +++ b/section1/exercises/ex6.rb @@ -0,0 +1,30 @@ +#define types_of_people +types_of_people = 10 +#define x +x = "There are #{types_of_people} types of people." +#define binary +binary = 'binary' +#define do_not +do_not = "don't" +#define y +y = "Those who know #{binary} and those who #{do_not}." +#outputs x +puts x +#outputs y +puts y +#outputs strings with x +puts "I said: #{x}" +#outputs string with y +puts "I also said: '#{y}'." +#define hilarious +hilarious = false +#define joke_evaluation +joke_evaluation = "Isn't that joke so funny?! #{hilarious}" +#outputs joke_evaluation +puts joke_evaluation +#defines w +w = "This is the left side of..." +#defines e +e = "a string with a right side." +#outputs w AND e +puts w + e diff --git a/section1/exercises/interpolation.rb b/section1/exercises/interpolation.rb index 2988c5181..65a31f353 100644 --- a/section1/exercises/interpolation.rb +++ b/section1/exercises/interpolation.rb @@ -15,16 +15,24 @@ speedy = "quick red fox" slow_poke = "lazy brown dog" -p # YOUR CODE HERE +puts "The #{speedy} jumped over the #{slow_poke}" # Write code that uses the variables below to form a string that reads # "In a predictable result, the tortoise beat the hare!": slow_poke = "tortoise" speedy = "hare" -# YOUR CODE HERE +puts "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. - +believe = "believe in a thing called love" +rhythm = "rhythm of my heart" +chance = "chance we could make it now" + +puts "I #{believe}" +puts "Just listen to the #{rhythm}" +puts "There's a #{chance}" +puts "We'll be rocking 'til the sun goes down" +puts "I #{believe}!!" diff --git a/section1/exercises/loops.rb b/section1/exercises/loops.rb index e8e69523e..0ce22d594 100644 --- a/section1/exercises/loops.rb +++ b/section1/exercises/loops.rb @@ -10,13 +10,16 @@ # Write code that prints the sum of 2 plus 2 seven times: 7.times do - # YOUR CODE HERE + puts 2 + 2 end # Write code that prints the phrase 'She sells seashells down by the seashore' # ten times: -# YOUR CODE HERE - +10.times do + puts "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 + puts 5 + 7 +end diff --git a/section1/exercises/numbers.rb b/section1/exercises/numbers.rb index 91435ffb2..f3f4345fa 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 +puts 83 - 7 # Write code that prints the result of 6 multiplied by 53: -# YOUR CODE HERE +puts 6 * 53 # Write code that prints the result of the modulo of 10 into 54: -# YOUR CODE HERE +puts 54 % 10 diff --git a/section1/exercises/strings.rb b/section1/exercises/strings.rb index b514a5a63..2816f2f6d 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 +puts "Welcome to Turing!" # Write code that prints `99 bottles of pop on the wall...` to the terminal: -# YOUR CODE HERE +puts "99 bottle 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. +puts "What's a twit?" diff --git a/section1/exercises/variables.rb b/section1/exercises/variables.rb index d765e886a..a3cd19aa2 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,64 @@ # 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 +puts 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 - +warning_dobby = "Harry Potter must not return to Hogwarts!" +puts warning_dobby # Write code that adds 2 to the `students` variable and # prints the result: students = 22 # YOUR CODE HERE p students - +new_count = students + 2 +puts new_count # Write code that subracts 2 from the `students` variable and # prints the result: # YOUR CODE HERE p students - +minus_students = students - 2 +puts minus_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 = "Joseph" +is_hungry = true +number_of_pets = 0 +puts first_name +puts is_hungry +puts number_of_pets # IN WORDS: -# How did you decide to use the data type you did for each of the three variables above? +# How did you decide to use the data type you did for each of the three variables above? # Explain. - +#first_name asks for name or string. is_hungry is asking true or false so I used a boolean data type. +#number_of_pets was asking for a number so I put an integer as the variable. # 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 = "Donny" +is_hungry = false +number_of_pets = 3 +puts first_name +puts is_hungry +puts 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; - +total_snacks = healthy_snacks + junk_food_snacks +puts total_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? +#Yes diff --git a/section1/reflection.md b/section1/reflection.md index 7ce0895a6..09e972c61 100644 --- a/section1/reflection.md +++ b/section1/reflection.md @@ -2,18 +2,38 @@ 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 really appreciated the author stating that teaching something was a part of the learning process. Once I feel like I can grasp something is the moment I feel like I can teach someone else. And usually, I end up learning more. I try to read as much as I can. Anything and everything. I would just say that I think a SuperLearner wants to pursue knowledge for knowledge sake. That they value any and all education. + 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? +The pound symbol: # + 1. Explain the difference between an integer and a float? +An integer is a whole number whereas a float contains a decimal. + 1. 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? +print animal + 1. What is interpolation? Use interpolation to print a sentence using the variable `animal`. +Interpolation uses variables within strings. +puts "My nephew loves to go to the zoo and see the #{animal}." + 1. What method is used to get input from a user? -1. Name and describe two common string methods: \ No newline at end of file +gets.chomps + +1. Name and describe two common string methods: + +.capitalize will change the first letter of the string to a capital letter and lowercase the rest +.downcase will change all the capital letters in a string to lowercase diff --git a/section2/README.md b/section2/README.md index b81832248..aacaea509 100644 --- a/section2/README.md +++ b/section2/README.md @@ -50,13 +50,13 @@ Using your terminal, open your local copy of the forked repository you created d 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/ex13.rb b/section2/exercises/ex13.rb new file mode 100644 index 000000000..d2cba4585 --- /dev/null +++ b/section2/exercises/ex13.rb @@ -0,0 +1,5 @@ +first, second, third = ARGV + +puts "Your first variable is: #{first}" +puts "Your second variable is: #{second}" +puts "Your third variable is: #{third}" diff --git a/section2/exercises/ex18.rb b/section2/exercises/ex18.rb new file mode 100644 index 000000000..df544a14c --- /dev/null +++ b/section2/exercises/ex18.rb @@ -0,0 +1,25 @@ +#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/ex19.rb b/section2/exercises/ex19.rb new file mode 100644 index 000000000..7185eb783 --- /dev/null +++ b/section2/exercises/ex19.rb @@ -0,0 +1,32 @@ +#defines the method cheese_and_crackers and defines the arguments +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 + +#put arguments when we call the method that define the variables +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 + +#using the above variables as the arguments we can temp define new variables +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) + +def movie_night(film, date_choice, trust) + puts "Let's watch #{film}!" + puts "I don't care for #{film}. How about #{date_choice}?" + puts "Let's meet in the middle with #{trust}." +end + +movie_night("Return of the Jedi", "A New Hope", "Empire Strikes Back") diff --git a/section2/exercises/ex21.rb b/section2/exercises/ex21.rb new file mode 100644 index 000000000..2368db88c --- /dev/null +++ b/section2/exercises/ex21.rb @@ -0,0 +1,38 @@ +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) +height = subtract(78, 4) +weight = multiply(90, 2) +iq = divide(100, 2) + +puts "Age: #{age}, Height: #{height}, Weight: #{weight}, IQ: #{iq}" + +#A puzzle for extra credit +puts "Here is a puzzle." + +what = add(age, subtract(height, multiply(weight, divide(iq, 2)))) + +puts "That becomes: #{what}. Can you do it by hand?" + +my_age = add(40 + 5) +puts "Therefore my age is #{my_age}." diff --git a/section2/exercises/ex29.rb b/section2/exercises/ex29.rb new file mode 100644 index 000000000..a46964a4f --- /dev/null +++ b/section2/exercises/ex29.rb @@ -0,0 +1,33 @@ +people = 20 +cats = 19 +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 += 6 + +if people >= dogs + puts "People are greater than or equal to dogs." +end + +if people <= dogs + puts "People are less or equal to dogs." +end + +if people == dogs + puts "People are dogs." +end diff --git a/section2/exercises/ex30.rb b/section2/exercises/ex30.rb new file mode 100644 index 000000000..010c0a009 --- /dev/null +++ b/section2/exercises/ex30.rb @@ -0,0 +1,28 @@ +#define variables +people = 20 +cars = 5 +trucks = 17 + +#this if statement is checking to see if cars are equal to people +#if true then print "We should take the cars." +if cars == people + puts "We should take the cars." +#this is telling the code if the above statement is false, check this statement +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/ex31.rb b/section2/exercises/ex31.rb new file mode 100644 index 000000000..85ff28f37 --- /dev/null +++ b/section2/exercises/ex31.rb @@ -0,0 +1,45 @@ +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" + puts "There is a giant bear here eating a cheesecake. What do you do?" + puts "1. Take the cake." + puts "2. Scream at the bear." + puts "3. Ask the bear if you can join." + + 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!" + elsif bear == "3" + puts "The bear is stunned by your manners and offers you some cheesecake." + else + puts "Well, doing %s is probably better. Bear runs away." % bear + end + +elsif door == "2" + puts "You stare into the endless abysss at Cthulu's retina." + puts "1. Blueberries." + puts "2. Yellow jacket clothespins." + puts "3. Understanding revolers yelling melodies." + puts "4. Blink." + + print "> " + insanity = $stdin.gets.chomp + + if insanity == "1" || insanity == "2" + puts "Your body survives powered by a mind of jello. Good job!" + elsif insanity == "4" + puts "What Cthulu? Guess it was your imagination." + 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/if_statements.rb b/section2/exercises/if_statements.rb index f29c45cdd..67ebb51bd 100644 --- a/section2/exercises/if_statements.rb +++ b/section2/exercises/if_statements.rb @@ -3,14 +3,14 @@ # 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" # if it is snowy, print "coat" # if it is icy, print "yak traks" - weather = 'snowy' + weather = 'windy' if weather == 'sunny' p "sunscreen" @@ -35,21 +35,23 @@ # 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 # to make sure both conditions can be achieved. -num_quarters = 0 +num_quarters = 3 +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 +63,13 @@ # Experiment with manipulating the value held within both variables # to make sure all above conditions output what you expect. -cups_of_flour = 1 +cups_of_flour = 5 has_sauce = true + +if cups_of_flour < 2 && has_sauce == true + puts "I cannot make a pizza" +elsif cups_of_flour >= 2 && has_sauce == false + puts "I cannot make a pizza" +elsif cups_of_flour >= 2 && has_sauce == true + puts "I can make a pizza" +end diff --git a/section2/exercises/methods.rb b/section2/exercises/methods.rb index f2517f1b3..1e2bf1a37 100644 --- a/section2/exercises/methods.rb +++ b/section2/exercises/methods.rb @@ -12,20 +12,34 @@ def print_name # Write a method that takes a name as an argument and prints it: def print_name(name) - # YOUR CODE HERE + puts "Look there! It's #{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 -# 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 sum(num1, num2) + puts "Really? #{num1 + num2} foxes?!" +end + +sum(6, 5) +sum(7, 1) +sum(2, 3) + +# 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 geograpy(city, state) + puts "#{city} is the capital of #{state}." +end + +geograpy("Springfield", "Illinois") +geograpy("Albany", "New York") +geograpy("Dover", "Delaware") #------------------- # PART 3: Naming is Hard @@ -38,4 +52,7 @@ def print_name(name) # What did you name each parameter, and why? # EXPLAIN: - +# I named the function geograpy because that is the purpose +# of the function and it is one word. I named the parameters such +# because that is the noun that describes them. Many people would +# know what I meant by city and state. diff --git a/section2/exercises/say.rb b/section2/exercises/say.rb new file mode 100644 index 000000000..574a0187d --- /dev/null +++ b/section2/exercises/say.rb @@ -0,0 +1,21 @@ +puts "hello" +puts "hi" +puts "how are you" +puts "I'm fine" + +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 diff --git a/section2/reflection.md b/section2/reflection.md index 49f0606df..43f482699 100644 --- a/section2/reflection.md +++ b/section2/reflection.md @@ -2,28 +2,73 @@ 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 am the type of person to hold off asking questions unless I am dying to know the answer. If the instructor says something that I do not understand, but I think that I should, I generally do not speak up. The reason is that I do not want to appear dumb. But more often than not, I find that others share the same question and I should not be afraid to ask. So I will wait until someone else asks my question for me. + ### If Statements 1. What is a conditional statement? Give three examples. +A conditional statement compares two values and decides if statement is true or false. +* if x == y +* if x > y +* if x || y + 1. Why might you want to use an if-statement? +An if statement can respond to a user input. If the program asks a Y/N question then the user can respond and the program checks to see what response was given and continue from there. + 1. What is the Ruby syntax for an if statement? +if conditional + do something +end + 1. How do you add multiple conditions to an if statement? +Either with elsif or else. + 1. Provide an example of the Ruby syntax for an if/elsif/else statement: +````ruby +if food == apple + puts "An apple a day!" +elsif food == banana + puts "Not my first choice." +else + puts "Ewww, gross!" +end +```` + 1. Other than an if-statement, can you think of any other ways we might want to use a conditional statement? +Maybe we could use converse, inverse, contrapositive to evaluate statements. + ### Methods 1. In your own words, what is the purpose of a method? +A method tells a program a set of instructions and gives the set a name so that programmers do not have to keep inputting the instructions again and again. + 1. Create a method named `hello` that will print `"Sam I am"`. +````ruby +def hello() + puts "Sam I am" +end +```` + 1. 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 +```` + 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 +`hello_someone` + +1. What questions do you have about methods in Ruby? + +No questions at this time. I just want to play around with methods some more and become more familiar with them. diff --git a/section3/README.md b/section3/README.md index ce954e76e..d67ad615e 100644 --- a/section3/README.md +++ b/section3/README.md @@ -38,13 +38,13 @@ Today you will learn about two common data structures: arrays and hashes. When you are all done with the lessons, exercises, and questions for today, you will once again use git to save your work locally, and then send your work to Github. 1. Work through the following lessons. Any files that you create while working can be kept in today's `exercises` directory. - - [ ] Read about what an [array](https://learnrubythehardway.org/book/ex32.html) is from Learn Ruby the Hard Way. + - [x] Read about what an [array](https://learnrubythehardway.org/book/ex32.html) is from Learn Ruby the Hard Way. - - [ ] Learn how arrays are [index-based](https://learnrubythehardway.org/book/ex34.html) from Learn Ruby the Hard Way. + - [x] Learn how arrays are [index-based](https://learnrubythehardway.org/book/ex34.html) from Learn Ruby the Hard Way. - - [ ] [Hashes](https://learnrubythehardway.org/book/ex39.html) from Learn Ruby the Hard Way. + - [x] [Hashes](https://learnrubythehardway.org/book/ex39.html) from Learn Ruby the Hard Way. - - [ ] [Hashes](http://tutorials.jumpstartlab.com/projects/ruby_in_100_minutes.html#8.-hashes) from Ruby in 100 minutes. + - [x] [Hashes](http://tutorials.jumpstartlab.com/projects/ruby_in_100_minutes.html#8.-hashes) from Ruby in 100 minutes. 1. Work through the arrays.rb file in the section3/exercises directory. diff --git a/section3/exercises/arrays.rb b/section3/exercises/arrays.rb index f710c6000..7b4cfbfe2 100644 --- a/section3/exercises/arrays.rb +++ b/section3/exercises/arrays.rb @@ -15,51 +15,71 @@ # EXAMPLE: write code below that will print an array of animals. # Store the array in a variable. animals = ["Zebra", "Giraffe", "Elephant"]; -print animals +puts animals +puts '-' * 10 # EXAMPLE: Write code below that will print "Zebra" from the animals array # YOUR CODE HERE -print animals[0] +puts animals[0] +puts '-' * 10 # YOU DO: Write code below that will print the number of elements in array of # animals from above. - +puts animals.length +puts '-' * 10 # YOU DO: Write code that will reassign the last item in the animals # array to "Gorilla" +animals[2] = "Gorilla" # YOU DO: Write code that will add a new animal (type of your choice) to position 3. +animals.push("Bobcat") # YOU DO: Write code that will print the String "Elephant" in the animals array - +animals.push("Elephant") +puts animals[4] +puts '-' * 10 #------------------- # PART 2: Foods: Array Methods #------------------- # YOU DO: Declare a variable that will store an an array of at least 4 foods (strings) +foods = ["grains", "veggies", "fruits", "meat"] # YOU DO: Write code below that will print the number of elements in the array of # foods from above. +puts foods.length +puts '-' * 10 # 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.push("broccoli") +puts foods +puts '-' * 10 # 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 +puts foods +puts '-' * 10 -# 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.push("sugar", "milk", "brownies") +puts foods # YOU DO: Remove the food that is in index position 0. +foods.shift + #------------------- # PART 3: Where are Arrays used? #------------------- @@ -77,11 +97,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: reddit has subreddits = ["epic fails", "cute pics", "explainlikeimfive"] +# 2: Youtube has videos = ["Go Easy on Me", "Rocketman", "Super Mario Secrets"] +# 3: Amazon has items = ["computers", "chairs", "books"] diff --git a/section3/exercises/ex32.rb b/section3/exercises/ex32.rb new file mode 100644 index 000000000..bdd5cf556 --- /dev/null +++ b/section3/exercises/ex32.rb @@ -0,0 +1,38 @@ +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 + +the_count.each do |number| + puts "This is the 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 to +# 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/ex39.rb b/section3/exercises/ex39.rb new file mode 100644 index 000000000..a23970eaf --- /dev/null +++ b/section3/exercises/ex39.rb @@ -0,0 +1,66 @@ +# 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 cites +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 a state +puts '-' * 10 +cities.each do |abbrev, city| + puts "#{abbrev} has the city #{city}." +end + +# now do both at the same time +puts '-' * 10 +states.each do |state, abbrev| + city = cities[abbrev] + puts "#{state} is abbreviated #{abbrev} and has the 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/hashes.rb b/section3/exercises/hashes.rb index 9d368c753..1e2922bd5 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,24 +8,26 @@ p foods # Write code that prints a hash holding zoo animal inventory: -zoo = #YOUR CODE HERE -p zoo +zoo = {camels: 4, rhinos: 3, snakes: 10} +puts 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 +puts zoo.keys -# 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 +puts zoo.values -# 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[:camels] -# 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[:polar_bear] = 4 + +puts '-' * 10 #------------------- @@ -41,15 +43,27 @@ # Write code that prints your email hash to the terminal. +email = { + sender: "Joseph", + receiver: "Lee", + subject: "Our date", + body: "I had a great time on Friday! Let's do it again!", + closing: "XOXO, Joseph" + } + +puts 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 -# Write code that prints all of the 'values' of the email hash +puts email.keys + +# Write code that prints all of the 'values' of the email hash # you created above: -# YOUR CODE HERE +puts email.values + +puts '-' * 10 #------------------- # Part 3: Many Emails - OPTIONAL EXTENSION @@ -64,7 +78,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 +90,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 +100,42 @@ } ] -puts posts -puts posts[0] +#puts posts +#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. + +sample_emails = [ + { + sender: "Mom", + receiver: "Joseph", + subject: "Don't forget.", + body: "To put on clean underwear everyday!!", + closing: "Love, Your worried Mom" + }, + { + sender: "Dad", + receiver: "Joseph", + subject: "Where did I put that?", + body: "Have you seen the remote? It was here last night.", + closing: "Love, Your confused Dad" + }, + { + sender: "Joseph", + receiver: "Boss", + subject: "I've been thinking", + body: "I do such a great job here. I think I should get a raise.", + closing: "With your approval, Joseph" + } +] + +puts sample_emails diff --git a/section3/reflection.md b/section3/reflection.md index cda726fd3..51a758224 100644 --- a/section3/reflection.md +++ b/section3/reflection.md @@ -2,16 +2,46 @@ 1. What are two points from the Growth Mindset article and/or video that either resonated with you, or were brand new to you? +* SMART or Setting Specific, Measurable, Achievable, Relevant, and +Time-bound goals. I feel like most of my life I have been told to make +lofty goals or they were not count. SMART is a way to grow and obtain +goals. +* That mistakes are part of the process. It seems like I punish myself +whenever I make a mistake. By saying that mistakes are part of the +process, it takes some pressure off. + 1. In which ways do you currently demonstrate a Growth Mindset? In which ways do you _not_? +* I like to stay in my comfort zone and do little things that push me out of that box, not big things that would freak me out. It is similar to the Zone of Proximal Development. +* I don't like to practice. To have a Growth Mindset it is important to practice your coding skills and then that is how to master it. + 1. What is a Hash, and how is it different from an Array? +A hash is a collection similar to an array. But a hash contains two pieces of information associated with each item where an array only has one. + 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. +````ruby +pet_store = { + "dog food" => 150, + "cat chow" => 120, + "fish flakes" => 300 +} +```` 1. Given the following `states = {"CO" => "Colorado", "IA" => "Iowa", "OK" => "Oklahoma"}`, how would you access the value `"Iowa"`? +`states["IA"]` + 1. With the same hash above, how would we get all the keys? How about all the values? +`states.keys` +`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? +* Say we had a group of first-graders and we wanted to associate each student with their favorite super hero. Using an array we could use the students' names as keys and the super heroes as values. +* An array would not let us associate the students with the super heroes. Using an array we could either access the student to find their favorite super hero or we could look up the super hero and see who loves them. + 1. What questions do you still have about hashes? + +None at this time. 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..8ea39bb3b 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,31 @@ def initialize(protein, base, toppings) @base = base @toppings = toppings end + + def add_topping(more_toppings) + @toppings = toppings << more_toppings + end + + def remove_topping(fewer_toppings) + toppings.delete(fewer_toppings) + end + + def change_protein(new_protein) + @protein = new_protein + end + end dinner = Burrito.new("Beans", "Rice", ["cheese", "salsa", "guacamole"]) p dinner.protein p dinner.base p dinner.toppings + +dinner.add_topping("lettuce") +p dinner.toppings + +dinner.remove_topping("salsa") +p dinner.toppings + +dinner.change_protein("Pork") +p dinner.protein diff --git a/section4/exercises/dog.rb b/section4/exercises/dog.rb index 03221314d..0b3a9369a 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,10 @@ def bark def eat @hungry = false end + + def play + @hungry = true + end end fido = Dog.new("Bernese", "Fido", 4) @@ -28,3 +32,5 @@ def eat p fido.hungry fido.eat p fido.hungry +fido.play +p fido.hungry diff --git a/section4/exercises/good_dog.rb b/section4/exercises/good_dog.rb new file mode 100644 index 000000000..92b0ec54c --- /dev/null +++ b/section4/exercises/good_dog.rb @@ -0,0 +1,20 @@ +class GoodDog + def initialize(name) + @name = name + end + + def get_name + @name + end + + def speak + "#{name} says Arf!" + end +end + +sparky = GoodDog.new("Sparky") +puts sparky.speak +puts sparky.get_name + +fido = GoodDog.new("Fido") +fido.speak diff --git a/section4/exercises/person.rb b/section4/exercises/person.rb index 2c26e9570..27f8eb912 100644 --- a/section4/exercises/person.rb +++ b/section4/exercises/person.rb @@ -1,5 +1,28 @@ -# 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 + + attr_reader :name, :eye_color + + def initialize(name, eye_color) + @name = name + @eye_color = eye_color + end + + def speak + puts "Hello, my name is #{name} and I have #{eye_color} eyes." + end + + def hobby + puts "#{name} likes to run 10 miles a day." + end + +end + +person1 = Person.new("Alex", "green") +puts person1.name +puts person1.eye_color +puts person1.speak +puts person1.hobby diff --git a/section4/exercises/student_class.rb b/section4/exercises/student_class.rb new file mode 100644 index 000000000..8d24b9168 --- /dev/null +++ b/section4/exercises/student_class.rb @@ -0,0 +1,16 @@ +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/reflection.md b/section4/reflection.md index 68b044b00..1ca9331ef 100644 --- a/section4/reflection.md +++ b/section4/reflection.md @@ -2,21 +2,51 @@ 1. How different did your workflow feel this week, considering we asked you to follow the Pomodoro technique? +* This was hard material to grasp. Taking a break every 25 minutes was very helpful. It let me think about something else and when I returned to the work, I felt like I was able to better understand the concept. Which actually made the work go smoother and swifter. + 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)? +* It was great to set a goal because then I had a stopping point. And when I reached that stopping point, I felt good about accomplishing the goal. I am really poor at estimating times, especially when it comes to learning something new. I had to read the readings several times for this section so my estimate on that was totally off. But I took comfort in knowing that I had a goal to get to. + 1. In your own words, what is a Class? +* A class is a type of data where you can tell Ruby that this piece of data has attributes and behaviors. For instance, books. A book has a title, author(s), publisher, and a genre. A class lets us those variables with books without having to re-define them over and over again. + 1. What is an attribute of a Class? +* An attribute is a variable of the class. Going off the example above, an attribute of the book class would be title. + 1. What is behavior of a Class? +* A behavior is an action defined by a method that a class can do. Generally, we do not think of books as doing actions by themselves. But you could make a method where we turn to chapter one. + 1. In the space below, create a Dog class with at least 2 attributes and 2 behaviors: -```rb +````rb +class Dog + attr_reader :name, :breed -``` + def initialize(name, breed) + @name = name + @breed = breed + end + + def speak + puts "Woof!" + end + + def drool + puts "Not on my new sheets!" + end + +end +```` 1. How do you create an instance of a class? -1. What questions do you still have about classes in Ruby? \ No newline at end of file +* Use the symbol `:` or `@` + +1. What questions do you still have about classes in Ruby? + +I not sure that I completely understand to be honest. I suppose I just need more exposure to it and it will come over time.