From 0e5ee38aee5c8678e207c9407ed4434893d740a2 Mon Sep 17 00:00:00 2001 From: Saba Bhamidipati Date: Mon, 25 Oct 2021 19:46:19 -0400 Subject: [PATCH 01/17] Add section1 --- section1/README.md | 2 +- section1/ex1.rb | 8 +++ section1/ex11.rb | 30 +++++++++ section1/ex2.rb | 1 + section1/ex3.rb | 23 +++++++ section1/ex4.rb | 33 +++++++++ section1/ex5.rb | 43 ++++++++++++ section1/ex6.rb | 67 +++++++++++++++++++ section1/exercises/booleans.rb | 3 + section1/exercises/interpolation.rb | 11 ++- section1/exercises/loops.rb | 11 +-- section1/exercises/numbers.rb | 6 +- section1/exercises/strings.rb | 10 ++- section1/exercises/variables.rb | 34 +++++++--- section1/reflection.md | 25 ++++++- section1/secretLibraryProject/README.md | 0 .../secretLibraryProject/lib/librarySystem.js | 0 section1/secretLibraryProject/lib/patron.js | 0 .../secretLibraryProject/lib/secretBook.js | 0 .../lib/secretLibrarian.js | 0 .../secretLibraryProject/lib/secretLibrary.js | 0 section1/secretLibraryProject/package.json | 0 .../test/librarySystems.js | 0 section1/secretLibraryProject/test/patron.js | 0 .../secretLibraryProject/test/secretBook.js | 0 .../secretLibraryProject/test/secretLibary.js | 0 .../test/secretLibrarian.js | 0 27 files changed, 282 insertions(+), 25 deletions(-) create mode 100644 section1/ex1.rb create mode 100644 section1/ex11.rb create mode 100644 section1/ex2.rb create mode 100644 section1/ex3.rb create mode 100644 section1/ex4.rb create mode 100644 section1/ex5.rb create mode 100644 section1/ex6.rb create mode 100644 section1/secretLibraryProject/README.md create mode 100644 section1/secretLibraryProject/lib/librarySystem.js create mode 100644 section1/secretLibraryProject/lib/patron.js create mode 100644 section1/secretLibraryProject/lib/secretBook.js create mode 100644 section1/secretLibraryProject/lib/secretLibrarian.js create mode 100644 section1/secretLibraryProject/lib/secretLibrary.js create mode 100644 section1/secretLibraryProject/package.json create mode 100644 section1/secretLibraryProject/test/librarySystems.js create mode 100644 section1/secretLibraryProject/test/patron.js create mode 100644 section1/secretLibraryProject/test/secretBook.js create mode 100644 section1/secretLibraryProject/test/secretLibary.js create mode 100644 section1/secretLibraryProject/test/secretLibrarian.js diff --git a/section1/README.md b/section1/README.md index 4239d2a0c..be2b90efd 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. diff --git a/section1/ex1.rb b/section1/ex1.rb new file mode 100644 index 000000000..090e2dd53 --- /dev/null +++ b/section1/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 'This is the "next" line in this exercise.' diff --git a/section1/ex11.rb b/section1/ex11.rb new file mode 100644 index 000000000..c056d0b1d --- /dev/null +++ b/section1/ex11.rb @@ -0,0 +1,30 @@ +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." + +# 1) gets prompts user input. .chomp blocks the new line (\n) creation when the + #'gets' value is used in a string +# 2) + +print "What's your first name? " +first_name = gets.chomp + +print "What's your last name? " +last_name = gets.chomp + +puts "Your name is #{first_name} #{last_name}." + +# 3) + +print "What's your favorite color? " +favorite_color = gets.chomp + +print "What's your t-shirt size? " +t_shirt_size = gets.chomp + +puts "You like to wear #{favorite_color} #{t_shirt_size} t-shirts!" diff --git a/section1/ex2.rb b/section1/ex2.rb new file mode 100644 index 000000000..935861847 --- /dev/null +++ b/section1/ex2.rb @@ -0,0 +1 @@ +puts 'Hi # there' diff --git a/section1/ex3.rb b/section1/ex3.rb new file mode 100644 index 000000000..cb00a56ab --- /dev/null +++ b/section1/ex3.rb @@ -0,0 +1,23 @@ +puts "I will now count my chickens:" + +puts "Hens #{25.0 + 30.0 / 6.0}" +puts "Roosters #{100.0 - 25.0 * 3.0 % 4.0}" + +puts "Now I will count the eggs:" + +puts 3.0 + 2.0 + 1.0 - 5.0 + 4.0 % 2.0 - 1.0 / 4.0 + 6.0 + +puts "Is it true that 3.0 + 2.0 < 5.0 - 7.0?" + +puts 3.0 + 2.0 < 5.0 - 7.0 + +puts "What is 3.0 + 2.0? #{3.0 + 2.0}" +puts "What is 5.0 - 7.0? #{5.0 - 7.0}" + +puts "Oh, that's why it's false." + +puts "How about some more." + +puts "Is it greater? #{5.0 > -2.0}" +puts "Is it greater or equal? #{5.0 >= -2.0}" +puts "Is it less or equal? #{5.0 <= -2.0}" diff --git a/section1/ex4.rb b/section1/ex4.rb new file mode 100644 index 000000000..29bc5cd51 --- /dev/null +++ b/section1/ex4.rb @@ -0,0 +1,33 @@ +cars = 100 +space_in_a_car = 4.0 +drivers = 30 +passengers = 90 + +# assigns calculation of cars not driven by subtracting drivers from total cars +cars_not_driven = cars - drivers + +# assigns number of drivers to cars_driven variable. Not sure why this was done, + # bc it's not used in the program. Maybe for consistency? +cars_driven = drivers + +#carpool capacity calculation assigned as cars_driven times space available +carpool_capacity = cars_driven * space_in_a_car + +#calculation of average passengers to be placed today +average_passengers_per_car = passengers / cars_driven + +puts "There are #{cars} cars available." +puts "There are only #{drivers} drivers available." +puts "There wil 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." + +# ruby found an error on line 14. When it says undefined local variable, it + # likely means that the variable 'carpool_capacity' has not been defined (created). + # Since 'carpool_capacity' was a calculation derived from other variables, it's + # likely that the input variables were defined, but the output variable 'carpool_capacity', + # was not. + +# 1. If the 'space_in_a_car' was assigned 4 instead of 4.0, the final answer would + # be an integer, but rounded to the nearest unit place diff --git a/section1/ex5.rb b/section1/ex5.rb new file mode 100644 index 000000000..9c499908d --- /dev/null +++ b/section1/ex5.rb @@ -0,0 +1,43 @@ +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}." + +name = 'Saba Bhamidipati' +age = 44 +height = 71 #inches +weight = 255 # lbs +eyes = 'Brown' +teeth = 'White' +hair = 'Salt & Pepper' + +puts "" +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 "If I add #{age}, #{height}, and #{weight} I get #{age + height + weight}." + +centimeters = 2.54 +grams = 454 +height_in_cms = height * centimeters +weight_in_grams = weight * grams + +puts "" +puts "His weight in centimeters is #{height_in_cms} cms." +puts "His height in grams is #{weight_in_grams} gms." diff --git a/section1/ex6.rb b/section1/ex6.rb new file mode 100644 index 000000000..5742e1b8a --- /dev/null +++ b/section1/ex6.rb @@ -0,0 +1,67 @@ +# assigns integer value to variable +types_of_people = 10 + +# nests integer inside string +x = "There are #{types_of_people} types of people." + +# assigns string value +binary = "binary" +# assigns string value +do_not = "don't" + +# nests string inside string x2 +y = "Those who know #{binary} and those who #{do_not}." + +# prints two strings +puts x +puts y + +# prints two nested strings inside nested strings +puts "I said: #{x}." +puts "I also said: '#{y}'." + +# assigns boolean value +hilarious = false + +# nests boolean value inside string +joke_evaluation = "Isn't that joke so funnny?! #{hilarious}" + +# prints string +puts joke_evaluation + +# concatenates two strings +w = "This is the left side of..." +e = "a string with a right side." + +# prints concatenated string +puts w + e + +# 2) 4 instances of strings nested in strings +# 3) Yes, sure. +# 4) adding w + e creates a concatenated string +# 5) I would guess they will not work when double switched to single, because it + # will confuse ruby on how things are nested. Also, tried doing it below + # after having run it, it does not work. +#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 funnny?! #{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/exercises/booleans.rb b/section1/exercises/booleans.rb index d3216d9d5..e1653c05b 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/interpolation.rb b/section1/exercises/interpolation.rb index 2988c5181..0ec004ff5 100644 --- a/section1/exercises/interpolation.rb +++ b/section1/exercises/interpolation.rb @@ -15,16 +15,21 @@ 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. +section1_progress = "slow" +is_done = false +hours_taken = 8 +puts "Saba's section 1 progress has been #{section1_progress}, and despite having + spent #{hours_taken} hours so far, his initial assumption that he would be done + by now, has proven #{is_done}!" diff --git a/section1/exercises/loops.rb b/section1/exercises/loops.rb index e8e69523e..7b11931f8 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..066184dda 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 53 * 6 # Write code that prints the result of the modulo of 10 into 54: -# YOUR CODE HERE +puts 10 % 54 diff --git a/section1/exercises/strings.rb b/section1/exercises/strings.rb index b514a5a63..390d79c9f 100644 --- a/section1/exercises/strings.rb +++ b/section1/exercises/strings.rb @@ -7,9 +7,13 @@ p "Alan Turing" # Write code that prints `Welcome to Turing!` to the terminal: -p #YOUR CODE HERE +example_2 = 'Welcome to Turing' +puts example_2 # Write code that prints `99 bottles of pop on the wall...` to the terminal: -# YOUR CODE HERE +example_3 = '99 bottles of pop on the wall...' +puts example_3 -# 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. +fave_line = 'you were gone for a long time' +puts fave_line diff --git a/section1/exercises/variables.rb b/section1/exercises/variables.rb index d765e886a..22f60b436 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,63 @@ # 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 +admonition = "Harry Potter must not return to Hogwarts!" +puts admonition # Write code that adds 2 to the `students` variable and # prints the result: students = 22 # YOUR CODE HERE -p students +p students + 2 # Write code that subracts 2 from the `students` variable and # prints the result: # YOUR CODE HERE -p students +p students - 2 # 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 = "Saba" +is_hungry = false +number_of_pets = 32 + +puts "It is #{is_hungry} that #{first_name} is hungry, and wants to eat his #{number_of_pets} 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. +# I wanted to interpolate the variables in a string, to see how they could form a sentence. # 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 = "SB" +is_hungry = true +number_of_pets = 23 +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; +puts "Total number of snack is #{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? +# Yes, I did. And I think, everything did print as I would've expected. diff --git a/section1/reflection.md b/section1/reflection.md index 7ce0895a6..2b048d348 100644 --- a/section1/reflection.md +++ b/section1/reflection.md @@ -2,18 +2,41 @@ 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? +Reading the article reinforced the idea that reading is an essential tool used by SuperLearners. I think I do read a fair amount, but the quality of my reading could use some improvement, i.e. books over articles. I think I need to really focus on my attention to detail. I think the one large thing I would add to the list would be consistency. Whether reading, attention to detail, or spotting differences, all of it requires consistency. + 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? +# + 1. Explain the difference between an integer and a float? +Floats are integers with decimal places + 1. In the space below, create a variable `animal` that holds the string `"zebra"` +animal = "zebra" + +# the single quotes are really throwing me off! Does the variable include the double quotes? + 1. 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`. +interpolation is the use of variables in a string. + +puts "The animal I am curious about the most, is 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 + +1. Name and describe two common string methods: + +.length gives you the number of characters in a string including spaces +.split splits a string into an array at any point where there are spaces diff --git a/section1/secretLibraryProject/README.md b/section1/secretLibraryProject/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secretLibraryProject/lib/librarySystem.js b/section1/secretLibraryProject/lib/librarySystem.js new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secretLibraryProject/lib/patron.js b/section1/secretLibraryProject/lib/patron.js new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secretLibraryProject/lib/secretBook.js b/section1/secretLibraryProject/lib/secretBook.js new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secretLibraryProject/lib/secretLibrarian.js b/section1/secretLibraryProject/lib/secretLibrarian.js new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secretLibraryProject/lib/secretLibrary.js b/section1/secretLibraryProject/lib/secretLibrary.js new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secretLibraryProject/package.json b/section1/secretLibraryProject/package.json new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secretLibraryProject/test/librarySystems.js b/section1/secretLibraryProject/test/librarySystems.js new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secretLibraryProject/test/patron.js b/section1/secretLibraryProject/test/patron.js new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secretLibraryProject/test/secretBook.js b/section1/secretLibraryProject/test/secretBook.js new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secretLibraryProject/test/secretLibary.js b/section1/secretLibraryProject/test/secretLibary.js new file mode 100644 index 000000000..e69de29bb diff --git a/section1/secretLibraryProject/test/secretLibrarian.js b/section1/secretLibraryProject/test/secretLibrarian.js new file mode 100644 index 000000000..e69de29bb From 0fc43755481da49c4ca2c17653b2bab57ca84510 Mon Sep 17 00:00:00 2001 From: Saba Bhamidipati Date: Mon, 25 Oct 2021 19:55:02 -0400 Subject: [PATCH 02/17] Change markdown in reflection --- section1/reflection.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/section1/reflection.md b/section1/reflection.md index 2b048d348..329af9fd7 100644 --- a/section1/reflection.md +++ b/section1/reflection.md @@ -39,4 +39,6 @@ gets 1. Name and describe two common string methods: .length gives you the number of characters in a string including spaces + + .split splits a string into an array at any point where there are spaces From 18742f131c55dca70601df1a6b19834b5d6e7c86 Mon Sep 17 00:00:00 2001 From: Saba Bhamidipati Date: Mon, 25 Oct 2021 19:56:49 -0400 Subject: [PATCH 03/17] Fix heading markdown in comment --- section1/reflection.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/section1/reflection.md b/section1/reflection.md index 329af9fd7..e9d0003ef 100644 --- a/section1/reflection.md +++ b/section1/reflection.md @@ -20,7 +20,7 @@ Floats are integers with decimal places animal = "zebra" -# the single quotes are really throwing me off! Does the variable include the double quotes? +the single quotes are really throwing me off! Does the variable include the double quotes? 1. How would you print the string `"zebra"` using the variable that you created above? From f2d1ba1d680309ac29663d95990f5deec850198b Mon Sep 17 00:00:00 2001 From: Saba Bhamidipati Date: Wed, 27 Oct 2021 22:37:33 -0400 Subject: [PATCH 04/17] Add Section 2 work --- section2/README.md | 6 ++-- section2/exercises/ex18.rb | 25 +++++++++++++ section2/exercises/ex19.rb | 30 ++++++++++++++++ section2/exercises/ex19a.rb | 35 ++++++++++++++++++ section2/exercises/ex21.rb | 40 +++++++++++++++++++++ section2/exercises/ex21a.rb | 21 +++++++++++ section2/exercises/ex29.rb | 46 ++++++++++++++++++++++++ section2/exercises/ex30.rb | 49 +++++++++++++++++++++++++ section2/exercises/ex31.rb | 56 +++++++++++++++++++++++++++++ section2/exercises/ex31a.rb | 41 +++++++++++++++++++++ section2/exercises/if_statements.rb | 28 ++++++++++----- section2/exercises/say.rb | 22 ++++++++++++ section2/reflection.md | 49 ++++++++++++++++++++++++- 13 files changed, 436 insertions(+), 12 deletions(-) create mode 100644 section2/exercises/ex18.rb create mode 100644 section2/exercises/ex19.rb create mode 100644 section2/exercises/ex19a.rb create mode 100644 section2/exercises/ex21.rb create mode 100644 section2/exercises/ex21a.rb create mode 100644 section2/exercises/ex29.rb create mode 100644 section2/exercises/ex30.rb create mode 100644 section2/exercises/ex31.rb create mode 100644 section2/exercises/ex31a.rb create mode 100644 section2/exercises/say.rb diff --git a/section2/README.md b/section2/README.md index b81832248..fa8e8c0c3 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,7 +44,7 @@ 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 @@ -68,7 +68,7 @@ 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. + - [ ] [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. diff --git a/section2/exercises/ex18.rb b/section2/exercises/ex18.rb new file mode 100644 index 000000000..d1c9da4d2 --- /dev/null +++ b/section2/exercises/ex18.rb @@ -0,0 +1,25 @@ +# this one is like 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..f0301b655 --- /dev/null +++ b/section2/exercises/ex19.rb @@ -0,0 +1,30 @@ +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 number 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/ex19a.rb b/section2/exercises/ex19a.rb new file mode 100644 index 000000000..83362921f --- /dev/null +++ b/section2/exercises/ex19a.rb @@ -0,0 +1,35 @@ +def time_spent_on_math(class_work, home_work) + puts "I spent #{class_work} minutes on class work!" + puts "I spent #{home_work} minutes on home work!" + if class_work + home_work > 80 + puts "WOW! That's way too much time!\n" + elsif class_work + home_work == 80 + puts "That's about right!\n" + elsif class_work + home_work < 80 + puts "Maybe you need to spend a little more time on math!\n" + end +end + +puts "Do I spend enough time on math?" +time_spent_on_math(40, 80) + +puts "Yesterday, I'm not sure I spent enough time on math" +cwork = 20 +hwork = 10 + +time_spent_on_math(cwork, hwork) + +puts "I added some time to my usual math work!" +time_spent_on_math(30 + 50, 25 + 55) + + +puts "Today was crazy with math work!" +time_spent_on_math(cwork + 5, hwork + 3) + +print "How much time do you spend on class work? " +cwork = gets.chomp.to_i + +print "How much time do you spend on home work? " +hwork = gets.chomp.to_i + +time_spent_on_math(cwork, hwork) diff --git a/section2/exercises/ex21.rb b/section2/exercises/ex21.rb new file mode 100644 index 000000000..d66de7eab --- /dev/null +++ b/section2/exercises/ex21.rb @@ -0,0 +1,40 @@ +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}" +# you can remove the return and it still works. Since this is a method, +# the calculation runs as part of the script/code block + 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 the extra credit, type it in anyway. +puts "Here is a puzzle." + +# using the return value of one function as the argument for a subsequent one +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/ex21a.rb b/section2/exercises/ex21a.rb new file mode 100644 index 000000000..f35e143b7 --- /dev/null +++ b/section2/exercises/ex21a.rb @@ -0,0 +1,21 @@ +def add(a, b) + puts "adding #{a} + #{b}" + return a + b +end + +addition = add(30, 14) + +puts addition + 10 + + +def hello(greeting) + puts greeting +end + +hello("Sam I am") + +def hello_someone(name) + puts "#{name} I am" +end + +hello_someone("Daffy Duck") diff --git a/section2/exercises/ex29.rb b/section2/exercises/ex29.rb new file mode 100644 index 000000000..5c0f41977 --- /dev/null +++ b/section2/exercises/ex29.rb @@ -0,0 +1,46 @@ +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 + +# 1) the if makes the statement conditional on the arguments being method + +# 2) the code under if needs to be indented because it is part of the conditional +# statement that provides the resulting output, when the condition is met + +# 3) I tried removing the indent and there was no impact. I thought the puts +# command might run regardless of the condition being met, but it did not. + +# 4) Not sure, didn't do ex27 + +# 5) If you change the initial values, it will change how the statements Are +# evaluated diff --git a/section2/exercises/ex30.rb b/section2/exercises/ex30.rb new file mode 100644 index 000000000..49642edcd --- /dev/null +++ b/section2/exercises/ex30.rb @@ -0,0 +1,49 @@ +people = 30 +cars = 40 +trucks = 15 + +# evaluates whether cars > people based on assigned values +if cars > people + +# if yes, the following will be printed + puts "We should take the cars." + +# if the prior condition is false, then this condition is tested +elsif cars < people + puts "We should not take the cars." + +# if both conditions are false, this statement will be printed +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 + +# 1) elsif is giving a follow-up conditional if the first one is false. And else +# else gives a final command if both if and elsif are false. + +# 2) if the numbers are different, the statements will be evaluated again, and +# outcomes may change + +# 3) || dbl pipe is a conditional OR, so either condition being true is sufficient for the +# condition to be successful + +if trucks > cars || cars > people + puts "That's too many trucks." +elsif trucks < cars + puts "Maybe we could take the trucks." +else + puts "We still can't decide." +end diff --git a/section2/exercises/ex31.rb b/section2/exercises/ex31.rb new file mode 100644 index 000000000..58835e5f2 --- /dev/null +++ b/section2/exercises/ex31.rb @@ -0,0 +1,56 @@ +puts "You enter a dark room with three doors. Do you go through door #1, door #2, or door #3?" + +print "> " +door = $stdin.gets.chomp + +if door == "1" + 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 + +elsif door == "3" + puts "You land in an aligator pit" + puts "1. Ride an aligator to the edge." + puts "2. Take a snake and beat the aligators with it." + puts "3. Take an aligator and beat the snakes with it." + + print "> " + uhoh = $stdin.gets.chomp + + if uhoh != "1" && uhoh != "2" + puts "Hold your breath and drown before you get eaten." + elsif uhoh == "1" + puts "Are you sure? Nvm! Too late! Aligator's cousin already fileted your leg." + else + puts "You're not serious, are you? Why would you do something so silly?!" + end + +else + puts "You stumble around and fall on a knife and die. Good job!" +end diff --git a/section2/exercises/ex31a.rb b/section2/exercises/ex31a.rb new file mode 100644 index 000000000..118b2fff8 --- /dev/null +++ b/section2/exercises/ex31a.rb @@ -0,0 +1,41 @@ +puts "You're falling through the sky. Should you take action 1, or action 2?" + +print "> " + +action = $stdin.gets.chomp + +if action == "1" + puts "You pulled the chute and it didn't work." + puts "1. Pull your backup chute." + puts "2. Unhook your tandem jumper." + + print "> " + + chute = $stdin.gets.chomp + + if chute == "1" + puts "Congratulations! You took the ONLY sane action you could!" + elsif chute == "2" + puts "REALLY?! If you make it to the ground, get help." + else + puts "Not even sure why you would do that." + end + +elsif action == "2" + puts "You found a magic ring that transports you to another dimension." + puts "1. You eat all the monkey brains." + puts "2. You ride the motorcycle over the rainbow, through the meadow, into your living room." + + print "> " + + magic = $stdin.gets.chomp + + if magic == "1" + puts "Get help. You found a magic ring and you ate monkey brains." + elsif magic == "2" || magic != "1" + puts "You already found a magic ring. Stop being greedy!" + end + +else + puts "You're falling through the sky. You don't have time to make up your own choices!!" +end diff --git a/section2/exercises/if_statements.rb b/section2/exercises/if_statements.rb index f29c45cdd..21545dd34 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,21 +35,27 @@ # 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 +print "Enter the number of quarters " +num_quarters = gets.chomp.to_i -puts "I have enough money for a gumball" -puts "I don't have enough money for a gumball" +if num_quarters == 0 + p "I don't have enough money for a gumball" +else num_quarters >= 0 + p "I have enough money for #{num_quarters} gumballs" +end +# puts "I have enough money for a gumball" +# puts "I don't have enough money for a gumball" ##################### # 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 +67,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 = 5 +has_sauce = false + +if cups_of_flour >= 2 && has_sauce == true + puts "I can make pizza" +else + puts "I cannot make pizza" +end diff --git a/section2/exercises/say.rb b/section2/exercises/say.rb new file mode 100644 index 000000000..eea9941a5 --- /dev/null +++ b/section2/exercises/say.rb @@ -0,0 +1,22 @@ +def say (words) + puts words + '.' +end + +say ("hello") +say ("why couldn't they name this stuff something easier?") +say ("why so many words that define each other?") + +def say(words='hello') + puts words + '.' +end + +say() +say("hi") +say("how are you") +say("I'm fine") + +# Method invocation with a block + +[1, 2, 3].each do |num| + puts num +end diff --git a/section2/reflection.md b/section2/reflection.md index 49f0606df..9015b19c1 100644 --- a/section2/reflection.md +++ b/section2/reflection.md @@ -2,28 +2,75 @@ 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 feel embarrassed about asking questions, and I always have. I either ask them too early in a process, or I wait for too long. When I ask early, it's likely because I'm overwhelmed by the task and I'm worried I won't be able to get started at all. When I wait too late, there's some overconfidence operating there, making me feel like that incremental 5 minutes is what I really need to crack the problem, even though i've already spent 80-100 mins on it. + ### If Statements 1. What is a conditional statement? Give three examples. +A conditional statement executes as blocks of code. The statement checks against the conditions in the IF portion. If that returns false, they continue on to the elsif and else portions. Only one portion of the code block will execute, once the true condition is found. Once that's the case, ruby will print the related output + 1. Why might you want to use an if-statement? +You may want to take inputs from the user, or test conditions in situations where variables are assigned different values 1. What is the Ruby syntax for an if statement? +if a == + puts +elsif + puts +else + puts +end + 1. How do you add multiple conditions to an if statement? +you can use && or || or use multiple elsif's 1. Provide an example of the Ruby syntax for an if/elsif/else statement: +if d == 0 + puts "d = 0" +elsif d > 0 + puts "d > 0" +else + puts "d < 0" +end + 1. Other than an if-statement, can you think of any other ways we might want to use a conditional statement? +I can't think of anything at the moment. + ### Methods 1. In your own words, what is the purpose of a method? +A method is a code block that runs multiple times in a program. It can be extracted to one place for efficiency. 1. Create a method named `hello` that will print `"Sam I am"`. +def hello(greeting) + puts greeting +end + +hello("Sam I am") + 1. Create a method named `hello_someone` that takes an argument of `name` and prints `"#{name} I am"`. +def hello_someone(name) + puts name + " I am" +end + +hello_someone("Daffy Duck") + +def hello_someone(name) + puts "#{name} I am" +end + +hello_someone("Daffy Duck") + 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 +When you pass an argument to the method, using the method definition and parameter, you run it + +1. What questions do you have about methods in Ruby? + +I need to go back over the concept of return, and understand why it isn't efficient to just run a calculation in a nested format, instead of assigning values to variables and then using their returned value to run other calculations. I imagine, for one thing, it would be neater, and easier for someone to look at and understand. From aa8123ff0ac1afb8f31a207d65372e2e355cd101 Mon Sep 17 00:00:00 2001 From: Saba Bhamidipati Date: Wed, 27 Oct 2021 22:45:36 -0400 Subject: [PATCH 05/17] Update markdown in reflection file --- final_prep/README.md | 10 +++++----- section2/reflection.md | 7 ++++++- section3/README.md | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/final_prep/README.md b/final_prep/README.md index 22bfb5154..f34fe4d95 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) ### 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? @@ -39,7 +39,7 @@ 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: + - [ ] Add link to your gist here: ### 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! @@ -49,7 +49,7 @@ You've learned a lot about how to take strong notes during Mod 0. Show us your s ### 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: + - [ ] Add a link to your gist here: ## 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/section2/reflection.md b/section2/reflection.md index 9015b19c1..7ae896911 100644 --- a/section2/reflection.md +++ b/section2/reflection.md @@ -55,14 +55,19 @@ hello("Sam I am") 1. Create a method named `hello_someone` that takes an argument of `name` and prints `"#{name} I am"`. + def hello_someone(name) + puts name + " I am" + end hello_someone("Daffy Duck") def hello_someone(name) + puts "#{name} I am" + end hello_someone("Daffy Duck") @@ -73,4 +78,4 @@ When you pass an argument to the method, using the method definition and paramet 1. What questions do you have about methods in Ruby? -I need to go back over the concept of return, and understand why it isn't efficient to just run a calculation in a nested format, instead of assigning values to variables and then using their returned value to run other calculations. I imagine, for one thing, it would be neater, and easier for someone to look at and understand. +I need to go back over the concept of return, and understand why it isn't efficient to just run a calculation in a nested format, instead of assigning values to variables and then using their returned value to run other calculations. I imagine, for one thing, it would be neater, and easier for someone to look at and understand. diff --git a/section3/README.md b/section3/README.md index d08a448b3..519870e7e 100644 --- a/section3/README.md +++ b/section3/README.md @@ -37,7 +37,7 @@ 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. +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. - [ ] Learn how arrays are [index-based](https://learnrubythehardway.org/book/ex34.html) from Learn Ruby the Hard Way. From f738542f55ddc17d7a32a9407404f520f542fb59 Mon Sep 17 00:00:00 2001 From: Saba Bhamidipati Date: Wed, 27 Oct 2021 22:48:38 -0400 Subject: [PATCH 06/17] Update more markdown in reflection file --- section2/reflection.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/section2/reflection.md b/section2/reflection.md index 7ae896911..8684ac793 100644 --- a/section2/reflection.md +++ b/section2/reflection.md @@ -16,24 +16,36 @@ You may want to take inputs from the user, or test conditions in situations wher 1. What is the Ruby syntax for an if statement? if a == + puts + elsif + puts + else + puts + end 1. How do you add multiple conditions to an if statement? -you can use && or || or use multiple elsif's + you can use && or || or use multiple elsif's 1. Provide an example of the Ruby syntax for an if/elsif/else statement: if d == 0 + puts "d = 0" + elsif d > 0 + puts "d > 0" + else + puts "d < 0" + end 1. Other than an if-statement, can you think of any other ways we might want to use a conditional statement? @@ -47,8 +59,10 @@ A method is a code block that runs multiple times in a program. It can be extrac 1. Create a method named `hello` that will print `"Sam I am"`. -def hello(greeting) +def hello(greeting + puts greeting + end hello("Sam I am") From 723d6ef5547929ded3fd4e9a540e0d4502d8707f Mon Sep 17 00:00:00 2001 From: Saba Bhamidipati Date: Fri, 29 Oct 2021 06:11:21 -0400 Subject: [PATCH 07/17] Add section 3 work --- section3/ex32.rb | 45 +++++++++++++++++++++++ section3/ex34.rb | 0 section3/ex39.rb | 70 ++++++++++++++++++++++++++++++++++++ section3/exercises/arrays.rb | 40 ++++++++++++++------- section3/exercises/hashes.rb | 54 ++++++++++++++++------------ section3/reflection.md | 23 ++++++++++++ 6 files changed, 198 insertions(+), 34 deletions(-) create mode 100644 section3/ex32.rb create mode 100644 section3/ex34.rb create mode 100644 section3/ex39.rb diff --git a/section3/ex32.rb b/section3/ex32.rb new file mode 100644 index 000000000..0bd7b31bd --- /dev/null +++ b/section3/ex32.rb @@ -0,0 +1,45 @@ +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 + +the_count.each do |number| + puts "The number is: #{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 teh 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 + +operator = [] + +(6...10).each do |a| + puts "adding #{a} to this list." + operator << a +end + +# now we can print them out too +elements.each {|i| puts "Element was: #{i}"} diff --git a/section3/ex34.rb b/section3/ex34.rb new file mode 100644 index 000000000..e69de29bb diff --git a/section3/ex39.rb b/section3/ex39.rb new file mode 100644 index 000000000..2ceb99f38 --- /dev/null +++ b/section3/ex39.rb @@ -0,0 +1,70 @@ +things = ['a','b','c','d'] + + +# 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 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 +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 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/arrays.rb b/section3/exercises/arrays.rb index f710c6000..69f2b84ec 100644 --- a/section3/exercises/arrays.rb +++ b/section3/exercises/arrays.rb @@ -19,46 +19,64 @@ # EXAMPLE: Write code below that will print "Zebra" from the animals array # YOUR CODE HERE -print animals[0] +puts animals[0] # YOU DO: Write code below that will print the number of elements in array of # animals from above. +puts "#{animals.count}" # YOU DO: Write code that will reassign the last item in the animals # array to "Gorilla" +animals[2] = "Gorilla" +print animals # YOU DO: Write code that will add a new animal (type of your choice) to position 3. +animals.push("Lion") +print animals -# YOU DO: Write code that will print the String "Elephant" in the animals array +# YOU DO: Write code that will print the String "Elephant" in the animals array +animals [2] = "Elephant" +puts animals[2] #------------------- # PART 2: Foods: Array Methods #------------------- # YOU DO: Declare a variable that will store an an array of at least 4 foods (strings) - +foods = ["lemons","oranges","chicken","pork"] +print foods # YOU DO: Write code below that will print the number of elements in the array of # foods from above. - +puts "#{foods.count}" # 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") +print 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.unshift("peas") +foods.insert(3, "carrots") +foods << "beef" +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 +95,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: Facebook has posts chronologically, and the date order is part of the storage protocol +# 2: My bank's app also uses a list ordered by date to track information +# 3: Amazon's order tracking page also uses lists to keep track of my order history diff --git a/section3/exercises/hashes.rb b/section3/exercises/hashes.rb index 9d368c753..a34e4749c 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,27 @@ p foods # Write code that prints a hash holding zoo animal inventory: -zoo = #YOUR CODE HERE +zoo = {giraffes: 2, lions: 1, monkeys: 10, parrots: 4} 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 +p 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 +p 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 +value = zoo.values[0] +p value -# 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['cheetah'] = 5 +p zoo #------------------- # Part 2: Email @@ -38,18 +40,26 @@ # 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 = { + 'Name' => 'Saba Bhamidipati', + 'Recepients' => 5, + 'Time Zone' => 'EST', + 'Attachments' => 2, + 'is_long' => false +} -# Write code that prints your email hash to the terminal. +puts email['Name'] +# Write code that prints your email hash to the terminal. +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 +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 #------------------- # Part 3: Many Emails - OPTIONAL EXTENSION @@ -64,7 +74,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 +86,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", @@ -90,12 +100,12 @@ 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. diff --git a/section3/reflection.md b/section3/reflection.md index cda726fd3..6af0df38d 100644 --- a/section3/reflection.md +++ b/section3/reflection.md @@ -2,16 +2,39 @@ 1. What are two points from the Growth Mindset article and/or video that either resonated with you, or were brand new to you? + The following points from the article resonated with me: + - Setting S.M.A.R.T. goals helps approach learning to code with clarity and focus. + - Believing that i can improve my cording skills with effort and practice, because growth mindset + is associated with mastery and learning oriented behaviors + 1. In which ways do you currently demonstrate a Growth Mindset? In which ways do you _not_? + I think I demonstrate growth mindset currently by pushing myself to go as deep as I can in each + section. As I get closer to the deadline, and I realize that I may need more time, on occasion I + solve for time over content. But for the vast majority of my time, I've been digging into as many of the details as possible, googling information, trying new strategies outside of what the + immediate task prescribes. 1. What is a Hash, and how is it different from an Array? + Hashes and Arrays are both indexed collections in Ruby. However, an Array is a list of data in a particular order, which can be called using that order. Data added or removed must also be done with the order prescribed. A Hash on the other hand is a list of data that does not have a particular order. It can contain any type of data, and it is a closer representation of object oriented programming because you can group all relevant data related to an object, within a particular Hash. A Hash can also be thought of as a table of elements. 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. + pet_store = {dog_food: 32, cat_food: 32, crates: 12, snacks: 123} + 1. Given the following `states = {"CO" => "Colorado", "IA" => "Iowa", "OK" => "Oklahoma"}`, how would you access the value `"Iowa"`? + puts states["IA"] + 1. 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? + We could use a hash to hold all customer information related to a credit card account. + + I think hashes are better because they can hold more varied information, adding/removing key-values is easier, and calling values is also easier + 1. What questions do you still have about hashes? + + I struggled mightily in this section!! WOW. This took so much longer than I expected. I realized that despite spending a good amount of time making notes, reading various tutorials online, and practicing here with exercises, I STILL struggle to add/remove values, call information, and sometimes even create hashes and arrays. I NEED practice, till all this is intuitive. While my immediate goal is to complete the prework, I have definitely created a running list of topics/exercises etc that I need to go back and review. Hashes and arrays are high on that list, because I know these will need to be second nature in Mod 1! From 37ccd80e51a4fd737796bd3727f4d66a88232a29 Mon Sep 17 00:00:00 2001 From: Saba Bhamidipati Date: Mon, 1 Nov 2021 22:08:44 -0400 Subject: [PATCH 08/17] Factor exercises --- section1/exercises/strings.rb | 6 ++++++ section1/exercises/variables.rb | 2 ++ 2 files changed, 8 insertions(+) diff --git a/section1/exercises/strings.rb b/section1/exercises/strings.rb index 390d79c9f..8f1aa974d 100644 --- a/section1/exercises/strings.rb +++ b/section1/exercises/strings.rb @@ -10,10 +10,16 @@ example_2 = 'Welcome to Turing' puts example_2 +puts 'Welcomg to Turing' + # Write code that prints `99 bottles of pop on the wall...` to the terminal: example_3 = '99 bottles of pop on the wall...' puts example_3 +puts '99 bottles of pop on the wall...' + # Write out code to log one line from your favorite song or movie. fave_line = 'you were gone for a long time' puts fave_line + +puts 'you were gone for a long time' diff --git a/section1/exercises/variables.rb b/section1/exercises/variables.rb index 22f60b436..e9198d292 100644 --- a/section1/exercises/variables.rb +++ b/section1/exercises/variables.rb @@ -57,6 +57,8 @@ puts is_hungry puts number_of_pets +puts "#{first_name}, #{is_hungry}, #{number_of_pets}" + # YOU DO: # Using the variables below, print the total number of snacks to the terminal: healthy_snacks = 6; From 61f289de9e6185facda3ae993cb369d742e492fe Mon Sep 17 00:00:00 2001 From: Saba Bhamidipati Date: Mon, 1 Nov 2021 22:09:47 -0400 Subject: [PATCH 09/17] Factor exercises --- section2/exercises/ex21.rb | 2 +- section2/exercises/methods.rb | 34 ++++++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/section2/exercises/ex21.rb b/section2/exercises/ex21.rb index d66de7eab..52baaf527 100644 --- a/section2/exercises/ex21.rb +++ b/section2/exercises/ex21.rb @@ -16,7 +16,7 @@ def multiply(a, b) def divide(a, b) puts "DIVIDING #{a} / #{b}" # you can remove the return and it still works. Since this is a method, -# the calculation runs as part of the script/code block +# the calculation runs as part of the script/code block a / b end diff --git a/section2/exercises/methods.rb b/section2/exercises/methods.rb index f2517f1b3..eaf5f69f4 100644 --- a/section2/exercises/methods.rb +++ b/section2/exercises/methods.rb @@ -12,30 +12,48 @@ 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 -# 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(num_1,num_2) + puts "#{num_1 + num_2}" +end + +sum(44,34) + +# 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 concatenated_string(string_1,string_2) + puts "#{string_1}" + " " + "#{string_2}" +end +concatenated_string("strings","are fun") +concatenated_string("on that","opinions differ") +concatenated_string("but practice","makes perfect") #------------------- # PART 3: Naming is Hard #------------------- - # Naming is notoriously hard in programming. It is a skill to name a variable or function concisely enough that it is reasonable to type, but descriptive enough that others can infer the meaning. # Look at the code you wrote for the previous YOU DO🎈 - what did you name the function, and why? + +# I named each function very literally, so that any user can tell that I read the instructions +# and followed them + # What did you name each parameter, and why? -# EXPLAIN: +# I named the parameters logically as well, because anyone assessing my work should be able to +# look at the instructions and see that I followed them +# EXPLAIN: From 2b17ee69dc8bc0945c3b68e2d99a23a0d067efc0 Mon Sep 17 00:00:00 2001 From: Saba Bhamidipati Date: Mon, 1 Nov 2021 22:11:28 -0400 Subject: [PATCH 10/17] Add Section4 Prework --- section4/exercises/burrito.rb | 15 ++++++++++++++- section4/exercises/dog.rb | 8 +++++++- section4/exercises/person.rb | 24 ++++++++++++++++++++++-- section4/reflection.md | 34 +++++++++++++++++++++++++++++++--- 4 files changed, 74 insertions(+), 7 deletions(-) diff --git a/section4/exercises/burrito.rb b/section4/exercises/burrito.rb index 967f68b6c..3f44c6e69 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,22 @@ def initialize(protein, base, toppings) @base = base @toppings = toppings end + + def add_topping(cheese) + puts + end + + def remove_topping() + end + + def change_protein() + end end dinner = Burrito.new("Beans", "Rice", ["cheese", "salsa", "guacamole"]) p dinner.protein p dinner.base p dinner.toppings + +# Quite honestly, this was a challenge I did not meet. I was confused by what was being asked. +# I will work on it once I have submitted work. diff --git a/section4/exercises/dog.rb b/section4/exercises/dog.rb index 03221314d..66f5b113c 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/person.rb b/section4/exercises/person.rb index 2c26e9570..7b12f5fc2 100644 --- a/section4/exercises/person.rb +++ b/section4/exercises/person.rb @@ -1,5 +1,25 @@ -# 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(height, weight, eye_color) + @height = height + @weight = weight + @eye_color = eye_color + end + + def say_height(inches) + @height = inches + puts "Your current height is #{inches} inches" + end + + def say_weight(pounds) + @weight = pounds + puts "Your current weight is #{pounds} pounds" + end +end + +Jermaine = Person.new(72, 240, 'green') +Jermaine.say_height(72) +Jermaine.say_weight(240) diff --git a/section4/reflection.md b/section4/reflection.md index 68b044b00..c48194777 100644 --- a/section4/reflection.md +++ b/section4/reflection.md @@ -2,21 +2,49 @@ 1. How different did your workflow feel this week, considering we asked you to follow the Pomodoro technique? + I used Pomodoro for compelting Section 4. Two things I struggled with: defining tasks with respect to coding, because I'm not sure how to break down the tasks. And the other, completing all tasks within the allotted time. It definitely helped to have brief breaks 2-3 mins in length. As an ongoing tool, I will need to spend more time defining tasks so I can break them into realistic and achievable chunks. + 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)? + As mentioned above, estimating time was difficult since I"m using it to learn completely new. The perceived time required was definitely off on several occasions. I think the method will become more useful as a tool once I have a better sense for tasks, and the time required + 1. In your own words, what is a Class? + A class is a tool to group specific methods meant to work together, on the same type of object. It's like a holding company with several functions like HR, Accounting, etc. They all service the subsidiaries (objects) and can be applied to multiple subsidiaries simultaneously. + 1. What is an attribute of a Class? + An attribute of a class is an instance variable. It can be applied to all objects in the class, and defines local variables. 1. What is behavior of a Class? + Behavior of a class is methods that are applicable to all objects in the class. Instance methods are mixed into objects via modules 1. In the space below, create a Dog class with at least 2 attributes and 2 behaviors: -```rb +``` + class LargeDogs + def initialize(name, height) + @name = name + @height = height + end -``` + def speak + "#{name} says his name while howling!" + end + def jump + "#{name} can jump at least as high as #{height} inches!" + end + end + + bruno = LargeDogs.new('Boxer', '60 lbs') + puts bruno.speak + puts bruno.jump +``` 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 + Once you've defined the attributes and methods of a class, you create an instance by declaring the object and using .new for the initial values + +1. What questions do you still have about classes in Ruby? + + As with the content in section 3, I need a TON of practice, creating classes, objects, methods and attributes! Running them and finding errors, fixing them, have been very useful. From d86bc8bd498ff5f21c6742767fa1da4697d2662c Mon Sep 17 00:00:00 2001 From: Saba Bhamidipati Date: Mon, 1 Nov 2021 22:12:34 -0400 Subject: [PATCH 11/17] Add Section4 Class_and_objects --- section4/exercises/classes_and_objects_1.rb | 39 +++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 section4/exercises/classes_and_objects_1.rb diff --git a/section4/exercises/classes_and_objects_1.rb b/section4/exercises/classes_and_objects_1.rb new file mode 100644 index 000000000..ac51410d4 --- /dev/null +++ b/section4/exercises/classes_and_objects_1.rb @@ -0,0 +1,39 @@ +class MyCar + attr_accessor :color + attr_reader :year + def initialize(year, model, color) + @year = year + @model = model + @color = color + @current_speed = 0 + end + + def speed_up(number) + @current_speed += number + puts "You push the gas pedal and accelerate #{number} mph" + end + + def brake(number) + @current_speed -= number + puts "You push the brake and decelerate #{number} mph" + end + + def current_speed + puts "You are now going #{@current_speed} mph" + end + + def shut_down + @current_speed = 0 + puts "Let's park the car" + end + + def spray_paint(color) + self.color = color + puts "Change your old color to #{color}" + end +end + +bmw = MyCar.new(1997, 'BMW', 'blue') +puts bmw.color +bmw.spray_paint("fuscia") +puts bmw.color From 17c3d1fef90886ebe7815d95370a1e6af4df5021 Mon Sep 17 00:00:00 2001 From: Saba Bhamidipati Date: Mon, 1 Nov 2021 22:14:30 -0400 Subject: [PATCH 12/17] Add Final Prep Changes --- final_prep/README.md | 14 ++-- final_prep/annotations.rb | 19 ++++- final_prep/mod_zero_hero.rb | 139 ++++++++++++++++++++++++++++++++++-- 3 files changed, 159 insertions(+), 13 deletions(-) diff --git a/final_prep/README.md b/final_prep/README.md index f34fe4d95..190ec2347 100644 --- a/final_prep/README.md +++ b/final_prep/README.md @@ -19,10 +19,10 @@ 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: @@ -39,17 +39,17 @@ 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: + - [ ] Add link to your gist here: https://gist.github.com/SabaBhamidipati/773b3a67dddd72f83da4be39d0271e8b ### 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: + - [ ] Add a link to your gist here: https://gist.github.com/SabaBhamidipati/56f3295a7f097af76ff225c7f57996f8 ### 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: + - [ ] Add a link to your gist here:https://gist.github.com/SabaBhamidipati/361a169fcab27e45ccee26e74e7eb010 ## 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. diff --git a/final_prep/annotations.rb b/final_prep/annotations.rb index 8b938706c..6079ae932 100644 --- a/final_prep/annotations.rb +++ b/final_prep/annotations.rb @@ -4,10 +4,16 @@ # Build a Bear +# create a method with multiple parameters def build_a_bear(name, age, fur, clothes, special_power) +# interpolation of name in greeting string value greeting = "Hey partner! My name is #{name} - will you be my friend?!" +# variable defined to combine dynamic variables name and age demographics = [name, age] +# dynamic variable that takes argument passed to it through object instance (not 100% sure bc I don't see a class creation here) power_saying = "Did you know that I can #{special_power}?" +# hash with keys that are attributes of a built bear, and values taken from combined variables +# along with a nested array that has three speech modes for the bear built_bear = { 'basic_info' => demographics, 'clothes' => clothes, @@ -19,25 +25,36 @@ def build_a_bear(name, age, fur, clothes, special_power) return built_bear end +# Two instances of build_a_bear class: Fluffy and Sleepy build_a_bear('Fluffy', 4, 'brown', ['pants', 'jorts', 'tanktop'], 'give you nightmares') build_a_bear('Sleepy', 2, 'purple', ['pajamas', 'sleeping cap'], 'sleeping in') # FizzBuzz +# define method with three parameters, two numbers and a max def fizzbuzz(num_1, num_2, range) +# inclusive range operator, that will iterate through each number (1..range).each do |i| +# modulo operator divides left number by both num_1 and num_2 and gets a remainder +# of 0, the i is a multiple of both, and it will return FizzBuzz if i % num_1 === 0 && i % num_2 === 0 puts 'fizzbuzz' +# if the modulo operator finds a 0 remainder for the left number and num1 ONLY, +# return 'fizz' elsif i % num_1 === 0 puts 'fizz' +# else if the modulo operator finds a 0 remainder for the left number and num2 ONLY, +# return 'buzz' elsif i % num_2 === 0 puts 'buzz' +# else if modulo operator finds a >0 remainder for both, return i value else puts i end end end +# two instances of fizzbuzz(factors 3,5,range 100) and (factors 5,8,range 400) 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..aa11971cf 100644 --- a/final_prep/mod_zero_hero.rb +++ b/final_prep/mod_zero_hero.rb @@ -2,45 +2,107 @@ # Declare two variables - hero_name AND special_ability - set to strings +hero_name = "Superman" +special_ability = "super strength" + +# puts hero_name +# puts special_ability + # 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, #{hero_name}" +catchphrase = "How is your #{special_ability} today?" + +# puts greeting +# puts catchphrase + # Declare two variables - power AND energy - set to integers +power = 100 +energy = 473 + # 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 * 100 +full_energy = energy + 150 + +# puts full_power +# puts full_energy + # Declare two variables - is_human and identity_concealed - assigned to booleans +is_human = false +identity_concealed = true + +# puts is_human +# puts identity_concealed # 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 = ['Lex Luthor', 'Brainiac', 'Darkseid', 'Doomsday'] +sidekicks = ['Supergirl', 'Lois Lane', 'Superboy'] + +# print arch_enemies +# puts '' +# print sidekicks + # Print the first sidekick to your terminal +# puts '' +puts sidekicks[0] # Print the last arch_enemy to the terminal +# puts'' +puts arch_enemies[3] # Write some code to add a new arch_enemy to the arch_enemies array +arch_enemies[4] = 'Bizarro' # 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 +arch_enemies.shift() + +# print arch_enemies # Print the sidekicks array to terminal to ensure you added a new sidekick +sidekicks[3] = 'Batman' +print 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) + + end + + assess_situation(0, "Cashapp please", "This is not a job for me") + # 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 # - 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 > 50 + puts bad_excuse + elsif danger_level >= 10 && danger_level <= 50 + puts save_the_day + else + puts "Meh. Hard pass." + end +end + +assess_situation(5, "Cashapp please", "This is not a job for me") + #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 +118,96 @@ # - luckyNumbers (array) # - address (hash with following key/values: number , street , state, zip) +scary_monster = { + + name: "Saba", + smell: "terrible", + weight: 250, + citiesDestroyed: ['Tokyo', 'Osaka', 'Hokkaido'], + luckyNumbers: [4, 15, 22], + address: {number: 580, street: "Lexington Ave", state: "New York", zip: 11002} + +} # 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 + attr_accessor :name, :super_power, :age + attr_reader :arch_nemesis, :power_level, :energy_level + def initialize(name, super_power, age, arch_nemesis, power_level, energy_level) + @name = name + @super_power = super_power + @age = age + @arch_nemesis = "The Syntax Error" + @power_level = 100 + @energy_level = 50 + end +end # - 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_accessor :name, :super_power, :age + attr_reader :arch_nemesis, :power_level, :energy_level + def initialize(name, super_power, age) + @name = name + @super_power = super_power + @age = age + @arch_nemesis = "The Syntax Error" + @power_level = 100 + @energy_level = 50 + end + + def say_name + puts "#{name}" + end + + def maximize_energy(level) + puts "energy_level is #{@energy_level*level}" + end + + def gain_power(add_power) + new_power = @power_level + add_power + puts "#{new_power}" + end +end + + # - Create 2 instances of your SuperHero class +superman = SuperHero.new('Superman', 'Super strength', 47) + +superwoman = SuperHero.new('Superwoman', 'Max speed', 40) # Reflection # What parts were most difficult about this exerise? +# First, I thought I had at least a working understanding of putting together methods, +# hashes, and classes. But the moment they become even slightly complicated, I feel +# like my knowledge base crumbles. It felt incredibly complicated to create a method +# with multiple parameters. Then inserting a conditional therein was also challenging. + +# Second, creating a class with static and dynamic values should have been much easier. +# But the moment I tried to initialize them, I realized I was making mistakes. It's incredible +# how important little details are. I realzied that I need to go back and spend a lot of time +# not just practicing these things, but rationalizing the logic behind them, and Then +# learn to make mistakes and fix them. I need to be conversant with hashes, arrays, classes, +# methods, and variations of all of these. It's going to be 70% practice, and 30% deciphering. # What parts felt most comfortable to you? +# I feel comfortable with conditionals, because they're not very different in Excel. # What skills do you need to continue to practice before starting Mod 1? - +# Time management! And going through ALL the Mod 1 prework, challenging myself to work through +# the exercises, and doing them far more autonomously. You really don't understand your gaps +# until you sit down to do comprehensive exercises that add layers of complexity. From 44e6afbb4f25ac3b5ec145546affee73c09f2dad Mon Sep 17 00:00:00 2001 From: Saba Bhamidipati Date: Mon, 1 Nov 2021 22:15:50 -0400 Subject: [PATCH 13/17] Update README.md --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 41a82f461..903747397 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Follow this guide step-by-step to make sure you have everything you need, then y - - ### Forking the Module 1 Prework Repository @@ -245,7 +245,7 @@ nothing to commit, working tree clean From here on out, all the work you do will be in your personal copy of this repository. Throughout Mod 0, we may call this your "prework repository" or "backend prework"... this refers to your forked copy of this `backend_mod_1_prework` repository that you have just now cloned to your device. ### IMPORTANT NOTE - PLEASE READ CAREFULLY -Do **NOT** work directly in the Github interface or use the `Edit` button to work directly from the Github version of your prework repository! +Do **NOT** work directly in the Github interface or use the `Edit` button to work directly from the Github version of your prework repository! Instead, add your work in your text editor (Atom) on your local machine (laptop) - your prework involves using `git` to track changes and push your work up to Github. We will cover how to do this in Mod 0 AND we give explicit instructions on how to do this in each section of the prework! @@ -256,4 +256,3 @@ Each day's `README` will walk you through the necessary steps to save your work. To begin, open your terminal and `cd` into the `section1` directory. Follow the instructions contained in the `README.md` file, and have fun experimenting! ---------------------------------- - From fa0422468755911439480ec9c68f0be60f88df0f Mon Sep 17 00:00:00 2001 From: Saba Bhamidipati <88849965+SabaBhamidipati@users.noreply.github.com> Date: Mon, 1 Nov 2021 22:19:59 -0400 Subject: [PATCH 14/17] Update README.md --- final_prep/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/final_prep/README.md b/final_prep/README.md index 190ec2347..d7fd25750 100644 --- a/final_prep/README.md +++ b/final_prep/README.md @@ -32,7 +32,8 @@ In Mod 0 you've learned about different techniques for managing your time at Tur When you are finished, add screenshots of your calendar so we can provide feedback if needed! -- `Add Week 1 Screenshot Here` +- `Add Week 1 Screenshot Here`Screen Shot 2021-11-01 at 7 08 29 PM + - `Add Week 2 Screenshot Here` - `Add Week 3 Screenshot Here` From 5e0c56bd46a97daaee878d12fc341da3b78dedb9 Mon Sep 17 00:00:00 2001 From: Saba Bhamidipati <88849965+SabaBhamidipati@users.noreply.github.com> Date: Mon, 1 Nov 2021 22:20:55 -0400 Subject: [PATCH 15/17] Update README.md --- final_prep/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/final_prep/README.md b/final_prep/README.md index d7fd25750..56401879c 100644 --- a/final_prep/README.md +++ b/final_prep/README.md @@ -34,8 +34,10 @@ When you are finished, add screenshots of your calendar so we can provide feedba - `Add Week 1 Screenshot Here`Screen Shot 2021-11-01 at 7 08 29 PM -- `Add Week 2 Screenshot Here` -- `Add Week 3 Screenshot Here` +- `Add Week 2 Screenshot Here`Screen Shot 2021-11-01 at 7 09 04 PM + +- `Add Week 3 Screenshot Here`Screen Shot 2021-11-01 at 7 09 22 PM + ### 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: From 39411fa48bcea2276a3a507546e4d084884d637a Mon Sep 17 00:00:00 2001 From: Saba Bhamidipati <88849965+SabaBhamidipati@users.noreply.github.com> Date: Mon, 1 Nov 2021 22:23:29 -0400 Subject: [PATCH 16/17] Update README.md --- final_prep/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/final_prep/README.md b/final_prep/README.md index 56401879c..c1bd1ba03 100644 --- a/final_prep/README.md +++ b/final_prep/README.md @@ -38,6 +38,8 @@ When you are finished, add screenshots of your calendar so we can provide feedba - `Add Week 3 Screenshot Here`Screen Shot 2021-11-01 at 7 09 22 PM + I received feedback in the past that my calendar needed more detail, especially with respect to tasks I plan to accomplish, which is fair. But the calendar referenced in the work, is for a different cohort, so I'm not sure what our tasks will be, by schedule, and it's hard to specify in my calendar without that clarity. + ### 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: From d8ba5340da9952132c4d6fd494ed53ca2373f239 Mon Sep 17 00:00:00 2001 From: Saba Bhamidipati Date: Mon, 8 Nov 2021 13:21:40 -0500 Subject: [PATCH 17/17] Complete Burrito Code --- section4/exercises/burrito.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/section4/exercises/burrito.rb b/section4/exercises/burrito.rb index 3f44c6e69..8627e3c40 100644 --- a/section4/exercises/burrito.rb +++ b/section4/exercises/burrito.rb @@ -12,21 +12,25 @@ def initialize(protein, base, toppings) @toppings = toppings end - def add_topping(cheese) - puts + def add_topping + puts "You can add the following toppings: #{toppings}" end - def remove_topping() + def remove_topping + puts "You can remove the following toppings: #{toppings}" end - def change_protein() + def change_protein + puts "Your protein options are the following: #{protein}" end end -dinner = Burrito.new("Beans", "Rice", ["cheese", "salsa", "guacamole"]) +dinner = Burrito.new(["Beans", "Carnitas", "Chicken", "Ropa Vieja"], ["Rice", "Lettuce", "Quinoa"], ["cheese", "salsa", "guacamole"]) p dinner.protein p dinner.base p dinner.toppings - +puts dinner.add_topping +puts dinner.remove_topping +puts dinner.change_protein # Quite honestly, this was a challenge I did not meet. I was confused by what was being asked. # I will work on it once I have submitted work.