From 2eb7b6a34f5f87c3e815cbd856034f0e54881cdb Mon Sep 17 00:00:00 2001
From: benistta <92293363+benistta@users.noreply.github.com>
Date: Wed, 27 Oct 2021 16:09:57 -0600
Subject: [PATCH 1/5] Add Section 1
---
section1/calculations_ex3.rb | 26 ++++++++++++++
section1/ex1.rb | 17 +++++++++
section1/ex2.rb | 18 ++++++++++
section1/ex3.rb | 36 +++++++++++++++++++
section1/ex4.rb | 55 +++++++++++++++++++++++++++++
section1/ex5.rb | 22 ++++++++++++
section1/ex6.rb | 37 +++++++++++++++++++
section1/ex7.rb | 22 ++++++++++++
section1/exercises/booleans.rb | 5 +--
section1/exercises/interpolation.rb | 8 +++--
section1/exercises/loops.rb | 11 ++++--
section1/exercises/numbers.rb | 5 +--
section1/exercises/strings.rb | 9 ++---
section1/exercises/variables.rb | 40 +++++++++++++--------
section1/reflection.md | 13 ++++++-
15 files changed, 296 insertions(+), 28 deletions(-)
create mode 100644 section1/calculations_ex3.rb
create mode 100644 section1/ex1.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/ex7.rb
diff --git a/section1/calculations_ex3.rb b/section1/calculations_ex3.rb
new file mode 100644
index 000000000..06508a2a7
--- /dev/null
+++ b/section1/calculations_ex3.rb
@@ -0,0 +1,26 @@
+#Print sentence 'I will now calculate Felipe's pay:'
+puts "I will now calculate Felipe's sales:"
+#Print the calculation in curly brackets
+puts "Felipe's sales on weekdays for a month #{30 + 20 - 3 % 5 / 4}"
+#Print the result of the calculation in curly brackets
+puts "Felipe's sales on weekends for a month #{3 + 76 / 7}"
+#Print sentence 'Now let's count his expenses:'
+puts "Now let's count his expenses:"
+#Print result of the calculation
+puts 4 + 5 + 7 - 8 / 12
+#Print question. Boolean
+puts "It is true that #{30 + 20 - 3 % 5 / 4} + #{3 + 76 / 7} > #{ 4 + 5 + 7 - 8 / 12}?"
+#Calculate and print the boolean answer. Either true or false
+puts (30 + 20 - 3 % 5 / 4) + (3 + 76 / 7) > 4+ 5 + 7 - 8 / 12
+#Print question and answer for the calculation in curly brackets
+puts "What is 50 + 13? #{50 + 13}"
+#Print question and answer for the calculation in curly brackets
+puts "What is 4 + 5 + 7 - 8 / 12? #{4 + 5 + 7 - 8 / 12}"
+#Print sentence 'Oh, now I understand.'
+puts "Oh, now I understand."
+#Print boolean question and answer for the calculation in curly brackets in boolean form: true or false
+puts "Is it greater? #{50 + 13 > 4 + 5 + 7 - 8 / 12}"
+#Print boolean question and answer for the calculation in curly brackets in boolean form: true or false
+puts "Is it greater or equal? #{50 + 13 >= 4 + 5 + 7 - 8 / 12}"
+#Print boolean question and answer for the calculation in curly brackets in boolean form: true or false
+puts "Is it less or equal? #{50 + 13 <= 4 + 5 + 7 - 8 / 12}"
diff --git a/section1/ex1.rb b/section1/ex1.rb
new file mode 100644
index 000000000..6bf239f01
--- /dev/null
+++ b/section1/ex1.rb
@@ -0,0 +1,17 @@
+# 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 "Making my script print another line"
+# Making my script print only one of the lines: I use # at the beggining of each line but one
+#puts "This is another line. What does putting a # character at the beginning of the line do? It makes it into a comment. It won't print.
+
+
+#Study drills
+#1. # Making my script print only one of the lines: I use # at the beggining of each line but one
+#puts "This is another line. #What does putting a # character at the beginning of the line do? It makes it into a comment. It won't print.
+#2. I made my script print only one of the lines by using the octothorpecharacter at the beginning of each line
+#3. It comments out the line.
diff --git a/section1/ex2.rb b/section1/ex2.rb
new file mode 100644
index 000000000..9d004b0a5
--- /dev/null
+++ b/section1/ex2.rb
@@ -0,0 +1,18 @@
+# A comment, this is so you can read your program later.
+# Anything after the # is ignored by ruby.
+
+puts "I could have code like this." # and the comment after is ignored
+
+# You can also use a comment to "disable" or comment out a piece of code:
+# puts "This won't run."
+
+puts "This will run."
+
+
+
+
+#Study Drills
+#1. I was right about what the octothorpe character does at the beginning of a line. It makes the line into a comment that won't print.
+#2. I reviewed each line going backward.
+#3. I fixed a couple of mistakes.
+#4. I read out loud what I typed and did not find more errors
diff --git a/section1/ex3.rb b/section1/ex3.rb
new file mode 100644
index 000000000..5b9bf5a05
--- /dev/null
+++ b/section1/ex3.rb
@@ -0,0 +1,36 @@
+#Print sentence 'I will now count my chickens:'
+puts "I will now count my chickens:"
+#Print the calculation in curly brackets for hens
+puts "Hens #{25.0 + 30.5 / 6.5}"
+#Print the result of the calculation in curly brackets for roosters
+puts "Roosters #{100.2 - 25.5 * 3.0 % 4.0}"
+#Print sentence 'Now I will count the eggs:'
+puts "Now I will count the eggs:"
+#Print result of the calculation
+puts 3.0 + 2.0 + 1.0 - 5.0 + 4.0 % 2.0 - 1.0 / 4.5 + 6.2
+#Print question. Boolean
+puts "It is true that 3.0 + 2.5 < 5.0 - 7.5?"
+#Calculate and print the boolean answer. Either true or false
+puts 3.0 + 2.5 < 5.0 - 7.5
+#Print question and answer for the calculation in curly brackets
+puts "What is 3.0 + 2.5? #{3.0 + 2.5}"
+#Print question and answer for the calculation in curly brackets
+puts "What is 5.0 - 7.5? #{5.0 - 7.5}"
+#Print sentence 'Oh, thats why it's false.'
+puts "Oh, thats why it's false."
+#Print sentence 'How about some more.'
+puts "How about some more."
+#Print boolean question and answer for the calculation in curly brackets in boolean form: true or false
+puts "Is it greater? #{5.5 > -2.5}"
+#Print boolean question and answer for the calculation in curly brackets in boolean form: true or false
+puts "Is it greater or equal? #{5.5 >= -2.5}"
+#Print boolean question and answer for the calculation in curly brackets in boolean form: true or false
+puts "Is it less or equal? #{5.5 <= -2.5}"
+
+#Study drills
+#1. used the octothorpe character (or pound) to write comments above each Line
+#2. irb(main):001:0> p 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6
+#7
+#=> 7
+#3. See calculations_ex3.#!/usr/bin/env ruby -wKU
+#4. Rewrote ex3.rb and used floating point numbers.
diff --git a/section1/ex4.rb b/section1/ex4.rb
new file mode 100644
index 000000000..be549474a
--- /dev/null
+++ b/section1/ex4.rb
@@ -0,0 +1,55 @@
+# write a variable for number of cars
+cars = 100
+# write a variable for how many people fit in the car
+space_in_a_car = 4.0
+#write a variable for number of drivers
+drivers = 30
+# write a variable for number of passengers
+passengers = 90
+# write a variable for a calculation that tells us how many cars have not been driven
+cars_not_driven = cars - drivers
+# write a variable for cars driven
+cars_driven = drivers
+# write a variable for carpool capacity. It will be calculation: cars driven * space in a car
+carpool_capacity = cars_driven * space_in_a_car
+# # write a variable for average_passengers_per_car. It will be calculation: passengers / cars_driven
+average_passengers_per_car = passengers / cars_driven
+
+# Print sentence 'There are (number of cars) cars available.'
+puts "There are #{cars} cars available."
+# Print sentence 'There are only (number of drivers) drivers available.'
+puts "There are only #{drivers} drivers available."
+# Print sentence 'There will be (calculation of cars not driven) empty cars today.'
+puts "There will be #{cars_not_driven} empty cars today."
+# Print sentence 'We can transport (calculation of carpool capacity) people today.'
+puts "We can transport #{carpool_capacity} people today."
+# Print sentence 'We have (number of passengers) to carpool today.'
+puts "We have #{passengers} to carpool today."
+# Print sentence 'We need to put about (average of passengers per car) in each car.'
+puts "We need to put about #{average_passengers_per_car} in each car."
+
+#Study drills:
+
+ #ex4.rb:14: undefined local variable or method `carpool_capacity' for
+ #main:Object (NameError)
+ #You might have gotten a "NameError" message if your variable hadn't yet been assigned to anything.
+#1. A floating number help us to have more accurate calculations. Just 4 would have worked also but it would't be a floating point number anymore.
+#2. Yes, 4 is an integer, while 4.0 is a floating point number.
+#3. Done
+#4. The single equals (=) assigns a value to a variable.
+#5. underscore character: (_)
+#6. irb(main):002:0> irb
+#irb#1(main):001:0> x = 5
+#=> 5
+#irb#1(main):002:0> i = 7
+#=> 7
+#irb#1(main):003:0> x + 7
+#=> 12
+#irb#1(main):004:0> j = 12
+#=> 12
+#irb#1(main):005:0> x % j / i
+#=> 0
+#irb#1(main):006:0> x % i
+#=> 5
+#irb#1(main):007:0> x % i * j
+#=> 60
diff --git a/section1/ex5.rb b/section1/ex5.rb
new file mode 100644
index 000000000..ba1861449
--- /dev/null
+++ b/section1/ex5.rb
@@ -0,0 +1,22 @@
+name = 'Zed A. Shaw'
+age = 35 # not a lie in 2009
+height = 74 * 2.54# inches converted to centimeters
+weight = 180 / 2.2046 # lbs converted to kilograms
+eyes = 'Blue'
+teeth = 'White'
+hair = 'Brown'
+
+puts "Let's talk about #{name}."
+puts "He's #{height} centimeters tall."
+puts "He's #{weight} kilograms 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."
+
+# this line is tricky, try to get it exactly right
+puts "If I add #{age}, #{height}, and #{weight} I get #{age + height + weight}."
+
+
+#Study Drills
+#1. I changed all the variables so there is no: my_
+#2. I wrote some variables that convert the inches and pounds to centimeters and kilograms.
diff --git a/section1/ex6.rb b/section1/ex6.rb
new file mode 100644
index 000000000..ffebaa76f
--- /dev/null
+++ b/section1/ex6.rb
@@ -0,0 +1,37 @@
+# Create a (type of people) variable and set it to number 10
+types_of_people = 10
+# Set x to 'There are (type of people variable) types of people'
+x = "There are #{types_of_people} types of people."
+#Create a binary variable and set it to 'binary'
+binary = "binary"
+#Create a (do not) variable and set it to 'don't
+do_not = "don't"
+#Set y to 'Those who know (binary) and those who (do not).'
+y = "Those who know #{binary} and those who #{do_not}."
+#Print x
+puts x
+#Print y
+puts y
+#Print 'I said: x.'
+puts "I said: #{x}."
+#Print 'I also said: 'y'.'
+puts "I also said: '#{y}'."
+#Create variable hilararious and set it to false
+hilarious = false
+#Create variable (joke evaluation) and set it to 'Isn't that joke so funny?! (hilarious)'
+joke_evaluation = "Isn't that joke so funny?! #{hilarious}"
+#Print joke evaluation
+puts joke_evaluation
+#Set w to 'This is the left side of...'
+w = "This is the left side of..."
+#Set e to 'a string with a right side.'
+e = "a string with a right side."
+#Concatenate w and e
+puts w + e
+
+#Study Drills
+#1. Used octothorpe character to make omments above each line explaining it.
+#2. Found all the places where a string is put inside a string:4
+#3. Yes, it was in 4 places
+#4. Because we are concatenating the string
+#5 They still work because uby knows when we want something to be a string when we use either double quotes or single quotes. We just need to pick one and be consistent.
diff --git a/section1/ex7.rb b/section1/ex7.rb
new file mode 100644
index 000000000..9685a8957
--- /dev/null
+++ b/section1/ex7.rb
@@ -0,0 +1,22 @@
+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."
+
+
+#Study drills
+#1. It returns a new String with the given record separator removed from the end of the str
+#2. To get a float input: gets.chomp.to_f and a integer input: gets.chomp.to_i
+#3.
+#print "Who are you? "
+#name = gets.chomp
+#print "What is your hobby? "
+#hobby = gets.chomp
+#print "Why you like doing that? "
+#why_hobby = gets.chomp
+
+#puts "So, you're #{name},you like #{hobby} and you like it because #{why_hobby}."
diff --git a/section1/exercises/booleans.rb b/section1/exercises/booleans.rb
index d3216d9d5..bd055bae9 100644
--- a/section1/exercises/booleans.rb
+++ b/section1/exercises/booleans.rb
@@ -9,7 +9,8 @@
p 7 > 2
# YOU DO: log to the console the result of "hello" is equal to "Hello":
-
+p "hello" === "Hello"
# YOU DO: log to the console the result of 3 is not equal to 4:
-
+p 3 != 4
# YOU DO: log to the console the result of 4 is less than or equal to 5:
+p 4 <= 5
diff --git a/section1/exercises/interpolation.rb b/section1/exercises/interpolation.rb
index 2988c5181..33d501010 100644
--- a/section1/exercises/interpolation.rb
+++ b/section1/exercises/interpolation.rb
@@ -15,7 +15,7 @@
speedy = "quick red fox"
slow_poke = "lazy brown dog"
-p # YOUR CODE HERE
+p "The #{speedy} jumped over the #{slow_poke}"# YOUR CODE HERE
# Write code that uses the variables below to form a string that reads
# "In a predictable result, the tortoise beat the hare!":
@@ -23,8 +23,12 @@
speedy = "hare"
# YOUR CODE HERE
-
+p "In a predictable result, the #{slow_poke} beat the #{speedy}!"
# YOU DO:
# Declare three variables, name/content/data type of your choice. Think carefully about what you name the variables. Remember, the goal is to be concise but descriptive (it's a hard balance!) Then, log out ONE sentence that incorporates all THREE variables.
+favorite_hobby = "salsa dancing"
+day_of_week = "Saturday"
+time_of_day = "night"
+p "I really want to go #{favorite_hobby} on #{day_of_week} #{time_of_day}"
diff --git a/section1/exercises/loops.rb b/section1/exercises/loops.rb
index e8e69523e..49d2d2f94 100644
--- a/section1/exercises/loops.rb
+++ b/section1/exercises/loops.rb
@@ -5,18 +5,23 @@
# Example: Write code that prints your name five times:
5.times do
- p "Hermione Granger"
+ p "Becky Nisttahuz"
end
# Write code that prints the sum of 2 plus 2 seven times:
7.times do
- # YOUR CODE HERE
+ p "2 + 2" # YOUR CODE HERE
end
# Write code that prints the phrase 'She sells seashells down by the seashore'
# ten times:
# YOUR CODE HERE
-
+10.times do
+ p 'She sells seashells down by the seashore'
+end
# Write code that prints the result of 5 + 7 a total of 9 timees
# YOUR CODE HERE
+9.times do
+ p 5 + 7
+end
diff --git a/section1/exercises/numbers.rb b/section1/exercises/numbers.rb
index 91435ffb2..26b585c03 100644
--- a/section1/exercises/numbers.rb
+++ b/section1/exercises/numbers.rb
@@ -7,10 +7,11 @@
p 2 + 2
# Write code that prints the result of 7 subtracted from 83:
-p #YOUR CODE HERE
+p 83 - 7#YOUR CODE HERE
# Write code that prints the result of 6 multiplied by 53:
# YOUR CODE HERE
-
+p 6 * 53
# Write code that prints the result of the modulo of 10 into 54:
# YOUR CODE HERE
+p 54 % 10
diff --git a/section1/exercises/strings.rb b/section1/exercises/strings.rb
index b514a5a63..f5d51e4c7 100644
--- a/section1/exercises/strings.rb
+++ b/section1/exercises/strings.rb
@@ -4,12 +4,13 @@
# `ruby section1/exercises/strings.rb`
# Example: Write code that prints your name to the terminal:
-p "Alan Turing"
+p "Becky Nisttahuz"
# Write code that prints `Welcome to Turing!` to the terminal:
-p #YOUR CODE HERE
+p "Welcome to Turing!"#YOUR CODE HERE
# Write code that prints `99 bottles of pop on the wall...` to the terminal:
# YOUR CODE HERE
-
-# Write out code to log one line from your favorite song or movie.
\ No newline at end of file
+p "99 bottles of pop on the wall..."
+# Write out code to log one line from your favorite song or movie.
+p "My precious."
diff --git a/section1/exercises/variables.rb b/section1/exercises/variables.rb
index d765e886a..2da3ac4d4 100644
--- a/section1/exercises/variables.rb
+++ b/section1/exercises/variables.rb
@@ -1,59 +1,71 @@
# 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
# prints what that variable holds to the terminal:
-name = "Harry Potter"
+name = "Becky Nisttahuz"
p name
# Write code that saves the string 'Dobby' to a variable and
# prints what that variable holds to the terminal:
house_elf = "Dobby"
# YOUR CODE HERE
-
+p house_elf
# Write code that saves the string 'Harry Potter must not return to Hogwarts!'
# and prints what that variable holds to the terminal:
# YOUR CODE HERE
-
+secret_message = "Harry Potter must not return to Hogwarts!"
+p secret_message
# 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`.
+first_name = "Becky"
+is_hungry = true
+number_of_pets = 1
+
+p first_name
+p is_hungry
+p number_of_pets
# Store the appropriate data types in each.
# print all three variables to the terminal.
# 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.
-
+For the first variable I decide to use a string since was asking for my first name. For the second one, since it started with is, I decided was a boolean. And for the last one I noticed it was a number data type.
# 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 = "Mario"
+is_hungry = false
+number_of_pets = 4
-
+p first_name
+p is_hungry
+p number_of_pets
# YOU DO:
# Using the variables below, print the total number of snacks to the terminal:
healthy_snacks = 6;
junk_food_snacks = 8;
-
+p healthy_snacks + junk_food_snacks
#-------------------
# FINAL CHECK
#-------------------
-# Did you run this file in your terminal to make sure everything printed out to the terminal
- # as you would expect?
\ No newline at end of file
+# Did you run this file in your terminal to make sure everything printed out to the terminal
+ # as you would expect?
diff --git a/section1/reflection.md b/section1/reflection.md
index 7ce0895a6..698a27742 100644
--- a/section1/reflection.md
+++ b/section1/reflection.md
@@ -2,18 +2,29 @@
1. How did the SuperLearner Article resonate with you? What from this list do you already do? Want to start doing or do more of? Is there anything not on this list, that you would add to it?
+I have put some thought on how I learn best. This article resonates with me since some of the things listed here are working for me or I think would work to enhance my learning process. Seeing learning as a process and seeing the importance of breaks is something I already do. I also read a lot but not enough I think, or at least not the kind of books that will help me with a specific topic. My reading usually has to do with Spanish literature. One of my goals for this cohort and for my future as a software developer in general is to do some more instructional reading, and get in the habit of doing that.
+I also will try and take better care of my brain. Sleeping well and eating will be one of my goals for this cohort. After a good night sleep I am more eager to learn and more attentive.
+
1. How would you print the string `"Hello World!"` to the terminal?
+puts "Hello World!"
1. What character is used to indicate comments in a ruby file?
+ #The octothorpe character
1. Explain the difference between an integer and a float?
+ An integer is a positive or negative number with no decimal point value. A float contains a decimal value
1. In the space below, create a variable `animal` that holds the string `"zebra"`
+ animal = "zebra"
1. How would you print the string `"zebra"` using the variable that you created above?
+p animal
1. What is interpolation? Use interpolation to print a sentence using the variable `animal`.
+ p "I don't know what sound a #{animal} makes"
1. What method is used to get input from a user?
+ get method
-1. Name and describe two common string methods:
\ No newline at end of file
+1. Name and describe two common string methods:
+ The length method will get the length of the string and the count method gets the count of characters of a string.
From 07cfb7a2ad4cd3c1ab8719dfd5c0046af5ce730e Mon Sep 17 00:00:00 2001
From: benistta <92293363+benistta@users.noreply.github.com>
Date: Mon, 1 Nov 2021 10:22:24 -0600
Subject: [PATCH 2/5] Add Section 2 work
---
section2/exercises/ex1_sec2.rb | 112 +++++++++++++++++++++
section2/exercises/ex2_sec2.rb | 107 ++++++++++++++++++++
section2/exercises/ex3_sec2.rb | 148 ++++++++++++++++++++++++++++
section2/exercises/ex4_sec2.rb | 30 ++++++
section2/exercises/ex5_sec2.rb | 76 ++++++++++++++
section2/exercises/ex6_sec2.rb | 118 ++++++++++++++++++++++
section2/exercises/if_statements.rb | 37 ++++++-
section2/exercises/methods.rb | 32 ++++--
section2/exercises/say.rb | 142 ++++++++++++++++++++++++++
section2/reflection.md | 39 +++++++-
10 files changed, 826 insertions(+), 15 deletions(-)
create mode 100644 section2/exercises/ex1_sec2.rb
create mode 100644 section2/exercises/ex2_sec2.rb
create mode 100644 section2/exercises/ex3_sec2.rb
create mode 100644 section2/exercises/ex4_sec2.rb
create mode 100644 section2/exercises/ex5_sec2.rb
create mode 100644 section2/exercises/ex6_sec2.rb
create mode 100644 section2/exercises/say.rb
diff --git a/section2/exercises/ex1_sec2.rb b/section2/exercises/ex1_sec2.rb
new file mode 100644
index 000000000..86e8692ee
--- /dev/null
+++ b/section2/exercises/ex1_sec2.rb
@@ -0,0 +1,112 @@
+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
+
+#Study drills
+#1. I think it tells to choose one option or the other.
+#2. I think it needs to be indentent to separate them from the rest of the script
+#3. I think that if isn't indented then it all gests confusing
+#4. Yes I can, it works:
+
+#people = 20
+#cats = 30
+#dogs = 15
+
+
+#if people < cats || people > dogs
+# puts "Too many cats! The world is doomed!"
+#end
+
+#if people > cats && people< dogs
+# puts "Not many cats! The wrold is saved!"
+#end
+
+#if people < dogs
+# puts "The wrold is drooled on!"
+#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
+
+#5. The numbers are compared and the code runs:
+
+#people = 50
+#cats = 70
+#dogs = 45
+
+
+#if people < cats
+# puts "Too many cats! The world is doomed!"
+#end
+
+#if people > cats
+# puts "Not many cats! The world is saved!"
+#end
+
+#if people < dogs
+# puts "The world is drooled on!"
+#end
+
+#if people > dogs
+# puts "The world is dry!"
+#end
+
+
+#dogs += 5
+
+#if people >= dogs
+# puts "People are greater than or equal to dogs."
+#end
+
+#if people <= dogs
+# puts "People are less than or equal to dogs."
+#end
+
+
+#if people == dogs
+# puts "People are dogs."
+#end
diff --git a/section2/exercises/ex2_sec2.rb b/section2/exercises/ex2_sec2.rb
new file mode 100644
index 000000000..79369196f
--- /dev/null
+++ b/section2/exercises/ex2_sec2.rb
@@ -0,0 +1,107 @@
+#Create variable people with value: 30
+people = 30
+#Create variable cars with value: 40
+cars = 40
+#Crreate variable trucks with value: 15
+trucks = 15
+
+ #if cars are more than people
+if cars > people
+ #then print "We should take the cars."
+ puts "We should take the cars."
+ #else if cars are less than people
+elsif cars < people
+ #then print "We should not take the cars."
+ puts "We should not take the cars."
+ #otherwise
+else
+ #print "We can't decide."
+ puts "We can't decide."
+ #end if statement
+end
+
+#if trucks are more than cars
+if trucks > cars
+#then print "That's too many trucks."
+ puts "That's too many trucks."
+#else if trucks are less than cars
+elsif trucks < cars
+#then print "Maybe we could take the trucks."
+ puts "Maybe we could take the trucks."
+#otherwise
+else
+#print "We still can't decide."
+ puts "We still can't decide."
+#end if statement
+end
+
+#if people are less than trucks
+if people < trucks
+#then print "That's too many trucks."
+ puts "Alright, let's just take the trucks."
+#otherwise
+else
+#print "Fine, let's stay home then."
+ puts "Fine, let's stay home then."
+#end if statement
+end
+
+
+ #Study drills
+ #1. elsif I think means else if, and else is telling us thats the end of the choices.
+ #2.
+ #people = 60
+ #cars = 45
+ #trucks = 70
+
+
+ #if cars > people
+ # puts "We should take the cars."
+ #elsif cars < people
+ # puts "We should not take the cars."
+ #else
+ # puts "We can't decide."
+ #end
+
+ #if trucks > cars
+ # puts "That's too many trucks."
+ #elsif trucks < cars
+ # puts "Maybe we could take the trucks."
+ #else
+ # puts "We still can't decide."
+ #end
+
+ #if people > trucks
+ # puts "Alright, let's just take the trucks."
+ #else
+ # puts "Fine, let's stay home then."
+ #end
+
+ #3.
+ #people = 30
+ #cars = 40
+ #trucks = 15
+
+
+ #if cars > people && cars < trucks
+ # puts "We should take the cars."
+ #elsif cars < people && trucks > people
+ # puts "We should not take the cars."
+ #else
+ # puts "We can't decide."
+ #end
+
+ #if trucks > cars || people > trucks
+ # puts "That's too many trucks."
+ #elsif trucks < cars && cars < people
+ # 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
+ #4. Above each line I wrote an English description of what the line does.
diff --git a/section2/exercises/ex3_sec2.rb b/section2/exercises/ex3_sec2.rb
new file mode 100644
index 000000000..d4b79233f
--- /dev/null
+++ b/section2/exercises/ex3_sec2.rb
@@ -0,0 +1,148 @@
+=begin
+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
+
+else
+ puts "You stumble around and fall on a knife and die. Good job!"
+end
+=end
+
+#Study drills
+
+#1. Make new parts of the game
+=begin
+puts "You enter a dark room with three doors. Do you go through door #1, door #2 o 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."
+ puts "3. Run like crazy"
+ puts "4. Fight the bear"
+ puts "5. Play dead"
+
+ print "> "
+ bear = $stdin.gets.chomp
+
+ if bear == "1" || "4"
+ puts "The bear eats your face off. Good job!"
+ elsif bear == "2" || "3"
+ 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 are on a survival show"
+ puts "1. Play the game."
+ puts "2. Quit and go home sleep."
+ puts "3. Ask for a vacation insted"
+
+ print "> "
+ survival_show = $stdin.gets.chomp
+
+ if survival_show == "1"
+ puts "You are eaten by a cocodrile. Good luck next time!"
+ elsif survival_show == "2"
+ puts "You dream you are being eaten by a cocodrile. Wake up!"
+ else
+ puts " Well probably doing %s is better. You go to Aruba!" % survival_show
+ end
+
+else
+ puts "You stumble around and fall on a knife and die. Good job!"
+end
+=end
+
+#2. Write a complete new game
+puts "You enter a haunted house on Halloween. You get to the end of the hall and see two doors. Do you go through door #1 or door #2?"
+
+print "> "
+door = $stdin.gets.chomp
+
+if door == "1"
+ puts "IT is there with a red balloon asking you if you want to float"
+ puts "1. Say no thank you and run away as fast as possible."
+ puts "2. Pop his ballon and pull his hair"
+ puts "3. Pretend you can't see or hear him"
+
+ print "> "
+ it = $stdin.gets.chomp
+
+ if it == "1"
+ puts "He is surprised by your politness but he decides to kill you nevertheless. Too bad!"
+ elsif it == "2"
+ puts "He catches up with you and takes revenge. Oh no!"
+ else
+ puts "Well, doing %s is probably better. IT is confused and decides to go scare someone else." % it
+ end
+
+elsif door == "2"
+ puts "Freddy Krueger is singing lullabies and preparing you a very comfortable bed with scented candles and a white sound machine."
+ puts "1. You try to figth it but the lullabies are so damn good..."
+ puts "2. You are an insomniac so you start to worry over things you have no control over."
+
+
+ print "> "
+ freddy = $stdin.gets.chomp
+
+ if freddy == "1"
+ puts "Oh no, you fell asleep! Fredy visits your dreams right away eager to be your worst nightmare!"
+ elsif freddy == "2"
+ puts "Freddy falls asleep trying to make you sleep. Good job, you are safe!"
+ else
+ puts "Wake up! You are dreaming!"
+ end
+
+else
+ puts "You are banned from the Haunted House forever!"
+end
diff --git a/section2/exercises/ex4_sec2.rb b/section2/exercises/ex4_sec2.rb
new file mode 100644
index 000000000..ee032e30d
--- /dev/null
+++ b/section2/exercises/ex4_sec2.rb
@@ -0,0 +1,30 @@
+# this one is like your scripts with ARGV
+def print_two(*args)
+ arg1, arg2 = args
+ puts "arg1: #{arg1}, arg2: #{arg2}"
+end
+
+# ok, that *args is actually pointless, we can just do this
+def print_two_again(arg1, arg2)
+ puts "arg1: #{arg1}, arg2: #{arg2}"
+end
+
+# this just takes one argument
+def print_one(arg1)
+ puts "arg1: #{arg1}"
+end
+
+# this one takes no arguments
+def print_none()
+ puts "I got nothin'."
+end
+
+
+print_two("Zed","Shaw")
+print_two_again("Zed","Shaw")
+print_one("First!")
+print_none()
+
+#Study drills
+
+#Imade index cards with the method checklist provided.
diff --git a/section2/exercises/ex5_sec2.rb b/section2/exercises/ex5_sec2.rb
new file mode 100644
index 000000000..f44d09ddc
--- /dev/null
+++ b/section2/exercises/ex5_sec2.rb
@@ -0,0 +1,76 @@
+=begin
+#Create a method called cheese_and_crackers that has two parameters.
+def cheese_and_crackers(cheese_count, boxes_of_crackers)
+#prints 'You have (cheese_count) cheeses!'
+ puts "You have #{cheese_count} cheeses!"
+#prints 'You have (boxes_of_crackers) boxes of crackers!'
+ puts "You have #{boxes_of_crackers} boxes of crackers!"
+#prints 'Man that's enough for a party!'
+ puts "Man that's enough for a party!"
+ #prints 'Get a blanket.\n'
+ puts "Get a blanket.\n"
+#end
+end
+
+#prints We can just give the function numbers directly:
+puts "We can just give the function numbers directly:"
+#we give the method numeral parameters
+cheese_and_crackers(20, 30)
+
+#prints 'OR, we can use variables from our script:'
+puts "OR, we can use variables from our script:"
+
+#Variable amount_of_cheese with value 10
+amount_of_cheese = 10
+#Variable amount_of_crackers with value 50
+amount_of_crackers = 50
+#include variables created as parameters
+cheese_and_crackers(amount_of_cheese, amount_of_crackers)
+
+#prints 'We can even do math inside too:'
+puts "We can even do math inside too:"
+#math equations inside our method
+cheese_and_crackers(10 + 20, 5 + 6)
+
+#print 'And we can combine the two, variables and math:'
+puts "And we can combine the two, variables and math:"
+#Adding variables and math inside our method
+cheese_and_crackers(amount_of_cheese + 100, amount_of_crackers + 1000)
+=end
+
+
+#Study drills
+#1. I went back through the script and type a comment above each line explaining in English what it does.
+#2. I did read each line backward
+#3. Write at least one more function of your own design, and run it 10 different ways.
+
+def my_shoes_and_dresses(num_of_shoes, num_of_dresses)
+ puts "I have #{num_of_shoes} pair of shoes!"
+ puts "I have #{num_of_dresses} dresses!"
+ puts "Let's donate some"
+end
+
+
+puts "Giving my method numbers directly (integers):"
+my_shoes_and_dresses(30, 40)
+
+puts "Using floating pint numbers"
+my_shoes_and_dresses(12.0, 20.0)
+
+puts "Using variables from my script:"
+shoe_count = 12
+dress_count = 18
+
+my_shoes_and_dresses(shoe_count, dress_count)
+
+
+puts "Doing math:"
+my_shoes_and_dresses(40 + 10, 3 +27)
+my_shoes_and_dresses(20/2, 15/3)
+my_shoes_and_dresses(shoe_count/dress_count, dress_count/shoe_count)
+my_shoes_and_dresses(10 * 2 * 1, 12 * 3 * 1)
+my_shoes_and_dresses(12 % 5, 24 % 5)
+my_shoes_and_dresses(4 ** 3, 5 ** 4)
+
+puts "Using variables and math:"
+my_shoes_and_dresses(shoe_count + 12, dress_count + 10)
diff --git a/section2/exercises/ex6_sec2.rb b/section2/exercises/ex6_sec2.rb
new file mode 100644
index 000000000..a5b2bb104
--- /dev/null
+++ b/section2/exercises/ex6_sec2.rb
@@ -0,0 +1,118 @@
+=begin
+def add(a, b)
+ puts "ADDING #{a} + #{b}"
+ return a + b
+end
+
+def subtract(a, b)
+ puts "SUBTRACTING #{a} - #{b}"
+ return a - b
+end
+
+def multiply(a, b)
+ puts "MULTIPLYING #{a} * #{b}"
+ return a * b
+end
+
+def divide(a, b)
+ puts "DIVIDING #{a} / #{b}"
+ return a / b
+end
+
+
+puts "Let's do some math with just functions!"
+
+age = add(30, 5)
+height = subtract(78, 4)
+weight = multiply(90, 2)
+iq = divide(100, 2)
+
+puts "Age: #{age}, Height: #{height}, Weight: #{weight}, IQ: #{iq}"
+
+
+# A puzzle for the extra credit, type it in anyway.
+puts "Here is a puzzle."
+
+what = add(age, subtract(height, multiply(weight, divide(iq, 2))))
+
+puts "That becomes: #{what}. Can you do it by hand?"
+
+
+#Study drills
+#1. If you aren't really sure what return does, try writing a few of your own functions and have them return some values. You can return anything that you can put to the right of an =.
+=begin
+def add (x,y)
+ puts "adding #{x} + #{y}"
+ return x + y
+end
+
+def multiply(x,y)
+ puts "multiplying #{x} * #{y}"
+ return x * y
+end
+=end
+
+#2.I tried to figure out the normal formula that would recreate this same set of operations.
+=begin
+35 + (74 – (50 / 2) * (180) )
+35 + (74 – (25) * (180))
+35 + (74 – 4500)
+35 + (-4426)
+– 4391
+=end
+
+
+#3. I tried to change it on purpose to make another value.
+
+def add(a, b)
+ puts "ADDING #{a} + #{b}"
+ return a + b
+end
+
+def subtract(a, b)
+ puts "SUBTRACTING #{a} - #{b}"
+ return a - b
+end
+
+def multiply(a, b)
+ puts "MULTIPLYING #{a} * #{b}"
+ return a * b
+end
+
+def divide(a, b)
+ puts "DIVIDING #{a} / #{b}"
+ return a / b
+end
+
+
+puts "Let's do some math with just functions!"
+
+age = add(30, 5)
+height = subtract(78, 4)
+weight = multiply(90, 2)
+iq = divide(100, 2)
+
+puts "Age: #{age}, Height: #{height}, Weight: #{weight}, IQ: #{iq}"
+
+
+# A puzzle for the extra credit, type it in anyway.
+puts "Here is a puzzle."
+
+what = add(age, subtract(height, multiply(weight, divide(iq, 2))))
+
+puts "That becomes: #{what}. Can you do it by hand?"
+
+what_to_do = add(age, subtract(divide(weight, multiply(iq, 2)), height))
+puts "We changed the order of the arguments!"
+
+#4. Write a simple formula and use the functions in the same way to calculate it.
+#d(((weight + 2)* 1)- 3)/1
+#(((180 + 2) *1)-3)/1
+#3 - 180 /1
+#- 179
+
+my_formula = divide(subtract(3, multiply(add(weight, 2), 1)), 1)
+puts "Is my formula working?"
+
+
+#5. I removed the word return and see if the script still works.
diff --git a/section2/exercises/if_statements.rb b/section2/exercises/if_statements.rb
index f29c45cdd..5435aa22e 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"
@@ -27,6 +27,19 @@
# Experiment with manipulating the value held in variable 'weather'
# to print something other than 'coat'
+weather = 'sunny'
+
+if weather == 'sunny'
+ p "sunscreen"
+elsif weather == 'rainy'
+ p "umbrella"
+elsif weather == 'snowy'
+ p "coat"
+elsif weather == 'icy'
+ p "yak traks"
+else
+ p "good to go!"
+end
##################
# Using the num_quarters variable defined below, determine
@@ -35,21 +48,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
+puts "Number of quarters?"
+num_quarters = $stdin.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 >= 2
+ puts "I have enough money for a gumball"
+else
+ puts "I don't have enough money for a gumball"
+end
#####################
# Using the variables defined below, write code that will tell you
-# if you have the ingredients to make a pizza. A pizza requires
+# if you have the ingredients to make a pizza. A pizza requires
# at least two cups of flour and sauce.
# You should be able to change the variables to achieve the following outputs:
@@ -61,5 +80,13 @@
# 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
+
+
+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/methods.rb b/section2/exercises/methods.rb
index f2517f1b3..b47c64da0 100644
--- a/section2/exercises/methods.rb
+++ b/section2/exercises/methods.rb
@@ -10,21 +10,38 @@ def print_name
print_name
+def print_my_name
+ p "Becky Nisttahuz"
+end
+
+print_my_name
+
# Write a method that takes a name as an argument and prints it:
def print_name(name)
# YOUR CODE HERE
+ p name
end
print_name("Albus Dumbledore")
-# Write a method that takes in 2 numbers as arguments and prints
+# Write a method that takes in 2 numbers as arguments and prints
# their sum. Then call your method three times with different arguments passed in:
# YOUR CODE HERE
+def added_nums(num1, num2)
+ p num1+num2
+end
+
+added_nums(6,2)
+# 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 my_concat_sentence(first_word, second_word)
+ p "I love #{first_word} because it is so much #{second_word}"
+end
+
+my_concat_sentence("Halloween", "fun")
-# 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.
#-------------------
@@ -33,9 +50,8 @@ def print_name(name)
# 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?
# What did you name each parameter, and why?
-# EXPLAIN:
-
+# EXPLAIN: I named my method my_concat_sentence because it tells whoever is reading it that it is my concatenated sentence. Basically given a clear understanding of what it is.
+#I named my parameters first_word ,second_word because it describes which one will be the first word and which one will be the second one. I thought it was more descriptive than str1, str2.
diff --git a/section2/exercises/say.rb b/section2/exercises/say.rb
new file mode 100644
index 000000000..79e7be754
--- /dev/null
+++ b/section2/exercises/say.rb
@@ -0,0 +1,142 @@
+#puts "hello"
+#puts "hi"
+#puts "how are you"
+#puts "I'm fine"
+
+
+=begin
+def say(words)
+ puts words
+end
+
+say("hello")
+say("hi")
+say("how are you")
+say("I'm fine")
+=end
+
+=begin
+def say(words)
+ puts words + '.' ## <= We only make the change here!
+end
+
+say("hello")
+say("hi")
+say("how are you")
+say("I'm fine")
+=end
+
+=begin
+def say(words='hello')
+ puts words + '.'
+end
+
+say()
+say("hi")
+say("how are you")
+say("I'm fine")
+=end
+=begin
+a = 5
+
+def some_method
+ a = 3
+end
+
+puts a
+=end
+
+=begin
+a = [1, 2, 3]
+
+def mutate(array)
+ array.pop
+end
+
+p "Before mutate method: #{a}"
+p mutate(a)
+p "After mutate method: #{a}"
+=end
+
+=begin
+def add_three(number)
+ number + 3
+end
+
+
+returned_value = add_three(4)
+puts returned_value
+=end
+
+=begin
+def add_three(number)
+ return number + 3
+ number + 4
+end
+
+returned_value = add_three(4)
+puts returned_value
+
+
+def multiply(num1, num2)
+ num1 * num2
+end
+
+multiply(add(20, 45), subtract(80, 10))
+=> 4550
+# returns 4550
+
+
+add(subtract(80, 10), multiply(subtract(20, 6), add(30, 5)))
+=> 560
+=end
+
+#Exercises:
+# 1.Write a program that prints a greeting message. This program should contain a method called greeting that takes a name as its parameter and returns a string.
+def greeting(my_name)
+ "Hello, I am " + my_name + ". What's your name?"
+end
+
+ puts greeting ("Becky Nisttahuz")
+
+ #2. What do the following expressions evaluate to?
+
+=begin
+x = 2
+# evaluates to 2
+
+puts x = 2
+# evaluates to nil
+
+p name = "Joe"
+# evaluates to "Joe"
+
+four = "four"
+# evaluates to "four"
+
+print something = "nothing"
+# evaluates to nil
+=end
+
+#3. Write a program that includes a method called multiply that takes two arguments and returns the product of the two numbers.
+def multiply(first_num, second_num)
+ first_num * second_num
+end
+
+puts multiply(200, 2)
+
+#4.What will the following code print to the screen?
+#It does not print anything
+
+#5. Edit the method definition in exercise #4 so that it does print words on the screen. What does it return now?
+def scream(words)
+ words = words + "!!!!"
+ puts words
+end
+
+scream("Yippeee")
+
+ #It returns nil
+
+ #6. What does the following error message tell you?
+ # You don't have the right number of arguments in the method you are calling.
diff --git a/section2/reflection.md b/section2/reflection.md
index 49f0606df..d6ac7c2cd 100644
--- a/section2/reflection.md
+++ b/section2/reflection.md
@@ -2,28 +2,63 @@
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 noticed that I tend to try and solve things on my own before asking. By reading these blogs, I realized that the time wasted on me trying to solve a problem on my own is not helping me, on the contrary, I am wasting time. It is okay to try and solve questions on my own. But when it is taking more than 20 minutes and I am not making any progress, I should probably reach out and ask someone. I also noticed that since english is not my first language it takes me longer than others to process in my head a well defined and grammar-correct question. I will have to practice question construction. I believe one idea that can help me is the rubber duck idea. I will definitely get one so I can practice vocabulary and how to ask questions.
+
### If Statements
1. What is a conditional statement? Give three examples.
+A conditional statement evaluates statements (usually true/false) Based on the outcome and if a specified condition is met, it runs a set of instructions. examples:
+ 1. You need all the ingredients to follow a recipe. Do you have all the ingredients?
+ 2. Can you drink at a bar? Are you at least 21?
+ 3. If you drink you cannot drive! Did you drink tonight?
+
1. Why might you want to use an if-statement?
+ To let the program know whether or not to execute a set of instructions based o0n the conditional outcome
1. What is the Ruby syntax for an if statement?
-
+ If the boolean expression evaluates to true then the block of code inside the if statement is executed. If it evaluates to false, then the first set of code after the end of the if statement is executed.
1. How do you add multiple conditions to an if statement?
+ With elsif between the if and else statements.
1. Provide an example of the Ruby syntax for an if/elsif/else statement:
+age = 120
+
+
+if age >= 21 && age <= 100
+ puts "You can drink!"
+elsif age >= 18 && age < 21
+ puts "Looks like you can vote but not drink yet"
+elsif age < 19
+ puts "I am sorry, no drinking for you!"
+else
+ puts "You can have a celebratory drink for getting to 100 or more years of age!"
+end
+
1. Other than an if-statement, can you think of any other ways we might want to use a conditional statement?
+ I would assume Unless would be another way, in case the condition results to be false.
### Methods
1. In your own words, what is the purpose of a method?
+The purpose of a method is to organize the code and be able to use and reuse the code without having to type it each time.
1. Create a method named `hello` that will print `"Sam I am"`.
+def hello
+ p "Sam I am"
+end
1. Create a method named `hello_someone` that takes an argument of `name` and prints `"#{name} I am"`.
+def hello_someone(name)
+ p "#{name} I am"
+end
1. How would you call or execute the method that you created above?
+By typing its name and passing in arguments: hello_someone and in parenthesis I would type out my input which would be the name.
+
+hello_someone(Becky)
-1. What questions do you have about methods in Ruby?
\ No newline at end of file
+1. What questions do you have about methods in Ruby?
+ Can we use blocks as parameters?
+ What are the other ways to call methods in Ruby?
From 2af0f8746d1242f04fa68cccf77b3c66632686d2 Mon Sep 17 00:00:00 2001
From: benistta <92293363+benistta@users.noreply.github.com>
Date: Tue, 2 Nov 2021 00:12:41 -0600
Subject: [PATCH 3/5] Add Section 3 work
---
section3/exercises/arrays.rb | 44 ++++++------
section3/exercises/ex1_sec3.rb | 43 ++++++++++++
section3/exercises/ex2_sec3.rb | 38 +++++++++++
section3/exercises/ex3_sec3.rb | 120 +++++++++++++++++++++++++++++++++
section3/exercises/hashes.rb | 62 ++++++++++++-----
section3/reflection.md | 11 +++
6 files changed, 281 insertions(+), 37 deletions(-)
create mode 100644 section3/exercises/ex1_sec3.rb
create mode 100644 section3/exercises/ex2_sec3.rb
create mode 100644 section3/exercises/ex3_sec3.rb
diff --git a/section3/exercises/arrays.rb b/section3/exercises/arrays.rb
index f710c6000..c2c0139ff 100644
--- a/section3/exercises/arrays.rb
+++ b/section3/exercises/arrays.rb
@@ -23,43 +23,49 @@
# YOU DO: Write code below that will print the number of elements in array of
# animals from above.
-
+print 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 << "Tiger"
+print animals
# YOU DO: Write code that will print the String "Elephant" in the animals array
-
+animals[2] = "Elephant"
+print animals
+print animals[2]
#-------------------
# PART 2: Foods: Array Methods
#-------------------
# YOU DO: Declare a variable that will store an an array of at least 4 foods (strings)
-
-
+food = ["apples", "celery", "pasta", "bread"]
+print food
# YOU DO: Write code below that will print the number of elements in the array of
# foods from above.
-
+print food.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
-
+food << "broccoli"
+print food
# 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
-
-
-# YOU DO: Write code to add 3 new foods to the array.
+food.delete_at(4)
+print food
+# 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
-
+food.push("chocolate", "crackers", "butter")
+print food
# YOU DO: Remove the food that is in index position 0.
-
+food.delete_at(0)
+print food
#-------------------
# PART 3: Where are Arrays used?
#-------------------
@@ -77,11 +83,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: iTunes groups together songs I like in a playlist
+# 2: In Venmo each user has an account with a list of friends and also a list of payments received and another of payments made
+# 3: My online banking app, has list of purchases I have made evry day.
diff --git a/section3/exercises/ex1_sec3.rb b/section3/exercises/ex1_sec3.rb
new file mode 100644
index 000000000..2c93f83dd
--- /dev/null
+++ b/section3/exercises/ex1_sec3.rb
@@ -0,0 +1,43 @@
+=begin
+the_count = [1, 2, 3, 4, 5]
+fruits = ['apples', 'oranges', 'pears', 'apricots']
+change = [1, 'pennies', 2, 'dimes', 3, 'quarters']
+
+# this first kind of for-loop goes through a list
+# in a more traditional style found in other languages
+the_count.each do |number|
+ puts "This is count #{number}"
+end
+
+# same as above, but in a more Ruby style
+# this and the next one are the preferred
+# way Ruby for-loops are written
+fruits.each do |fruit|
+ puts "A fruit of type: #{fruit}"
+end
+
+# also we can go through mixed lists too
+# note this is yet another style, exactly like above
+# but a different syntax (way to write it).
+change.each {|i| puts "I got #{i}" }
+
+# we can also build lists, first start with an empty one
+elements = []
+
+# then use the range operator to do 0 to 5 counts
+(0..5).each do |i|
+ puts "adding #{i} to the list."
+ # pushes the i variable on the *end* of the list
+ elements << i
+end
+
+# now we can print them out too
+elements.each {|i| puts "Element was: #{i}" }
+
+
+#Study drills:
+#1. Look up Ruby's "range operator" (.. and ...) online to see what it does.
+#Ruby's "range operator" is used to create a sequence of specified elements. (..) is used to create an inclusive specified sequence range, while the (...) creates a range that excludes the specified high value.
+#2. I went to line 7 and changed the first for number in the_count to be a more typical .each style loop like the others.
+#3. Ruby info on arrays: https://ruby-doc.org/core-2.2.0/Array.html. Other than the << append operation, you can sort arrays, reverse them, you can get the length of the array, take specific elements out and more.
+ #I also tried << instead of push above (line 31)
diff --git a/section3/exercises/ex2_sec3.rb b/section3/exercises/ex2_sec3.rb
new file mode 100644
index 000000000..e6060ed98
--- /dev/null
+++ b/section3/exercises/ex2_sec3.rb
@@ -0,0 +1,38 @@
+=begin
+animals = ['bear', 'ruby', 'peacock', 'kangaroo', 'whale', 'platypus']
+
+
+The animal at 1. => ruby. The animal at 1 is ruby
+The third (3rd) animal. => The third animal is at 2 and is peacock
+The first (1st) animal. => The first animal is at 0 and is bear
+The animal at 3. The animal at 3 is kangaroo
+The fifth (5th) animal. The fifth animal is at 4 and is whale
+The animal at 2. The animal at 2 is peacock
+The sixth (6th) animal. The sixth animal is at 5 and is platypus
+The animal at 4. The animal at 4 is whale
+=end
+
+#Study drills
+#1. With what you know of the difference between these types of numbers, can you explain why the year 2010 in "January 1, 2010," really is 2010 and not 2009? (Hint: you can't pick years at random.)
+ #Because you cant pick years at random. You have to use ordinal numbers not cardinals. Years go on orden.
+#2. Write some more arrays and work out similar indexes until you can translate them.
+
+
+ music_genres = ['salsa', 'folk', 'country', 'pop', 'romantic']
+
+ puts "The third music genre is #{music_genres[2]}" #=> country
+ puts "The fifth music genre is #{music_genres[4]}" #=> romantic
+ puts "The second music genre is #{music_genres[1]}" #=> folk
+ puts "The first music genre is #{music_genres[0]}" #=> salsa
+ puts "The fourth music genre is #{music_genres[3]}" #=> pop
+
+
+
+#3. Use Ruby to check your answers.
+
+#The third music genre is country
+#The fifth music genre is romantic
+#The second music genre is folk
+#The first music genre is salsa
+#The fourth music genre is pop
+#Beckys-MacBook-Pro:exercises beckynisttahuz$
diff --git a/section3/exercises/ex3_sec3.rb b/section3/exercises/ex3_sec3.rb
new file mode 100644
index 000000000..f390a1ff1
--- /dev/null
+++ b/section3/exercises/ex3_sec3.rb
@@ -0,0 +1,120 @@
+=begin
+?> things = ['a', 'b', 'c', 'd']
+=> ["a", "b", "c", "d"]
+>> puts things[1]
+b
+=> nil
+>> things[1] = 'z'
+=> "z"
+>> puts things[1]
+z
+=> nil
+>> things
+=> ["a", "z", "c", "d"]
+=end
+
+# create a mapping of state to abbreviation
+states = {
+ 'Oregon' => 'OR',
+ 'Florida' => 'FL',
+ 'California' => 'CA',
+ 'New York' => 'NY',
+ 'Michigan' => 'MI'
+}
+
+# create a basic set of states and some cities in them
+cities = {
+ 'CA' => 'San Francisco',
+ 'MI' => 'Detroit',
+ 'FL' => 'Jacksonville'
+}
+
+# add some more cities
+cities['NY'] = 'New York'
+cities['OR'] = 'Portland'
+
+# puts out some cities
+puts '-' * 10
+puts "NY State has: #{cities['NY']}"
+puts "OR State has: #{cities['OR']}"
+
+# puts some states
+puts '-' * 10
+puts "Michigan's abbreviation is: #{states['Michigan']}"
+puts "Florida's abbreviation is: #{states['Florida']}"
+
+# do it by using the state then cities dict
+puts '-' * 10
+puts "Michigan has: #{cities[states['Michigan']]}"
+puts "Florida has: #{cities[states['Florida']]}"
+
+# puts every state abbreviation
+puts '-' * 10
+states.each do |state, abbrev|
+ puts "#{state} is abbreviated #{abbrev}"
+end
+
+# puts every city in state
+puts '-' * 10
+cities.each do |abbrev, city|
+ puts "#{abbrev} has the city #{city}"
+end
+
+# now do both at the same time
+puts '-' * 10
+states.each do |state, abbrev|
+ city = cities[abbrev]
+ puts "#{state} is abbreviated #{abbrev} and has city #{city}"
+end
+
+puts '-' * 10
+# by default ruby says "nil" when something isn't in there
+state = states['Texas']
+
+if !state
+ puts "Sorry, no Texas."
+end
+
+# default values using ||= with the nil result
+city = cities['TX']
+city ||= 'Does Not Exist'
+puts "The city for the state 'TX' is: #{city}"
+
+#Study drills
+#1.
+
+
+states_bolivia = {
+ 'La Paz' => 'LP',
+ 'Oruro' => 'OR',
+ 'Potosi' => 'PT',
+ 'Santa Cruz' => 'SC',
+ 'Beni' => 'BE',
+ 'Pando' => 'PD',
+ 'Tarija' => 'TA',
+ 'Chuquisaca' => 'CH',
+ 'Cochabamba' => 'CO'
+}
+
+
+capitals_states = {
+ 'LP' => 'Ciudad de La Paz',
+ 'OR' => 'Ciudad de Oruro',
+ 'PT' => 'Ciudad de Potosi',
+ 'SC' => 'Santa Cruz de la Sierra',
+ 'BE' => 'Trinidad',
+ 'PD' => 'Cobija',
+ 'TA' => 'San Bernardo de Tarija',
+ 'CH' => 'Sucre',
+ 'CO' => 'Ciudad de Cochabamba'
+}
+
+puts '-' * 10
+states_bolivia.each do |state, abbrev|
+ capital = capitals_states[abbrev]
+ puts "#{state} is abbreviated #{abbrev} and it's capital is #{capital}"
+end
+
+
+#2. https://ruby-doc.org/core-2.5.1/Hash.html I tried states_bolivia.invert
+#3. I looked to see if we could reverse a hash but couldnt find a straight answer on the matter. Since they do not have order I assume it would be hard to do that.
diff --git a/section3/exercises/hashes.rb b/section3/exercises/hashes.rb
index 9d368c753..3c0b53763 100644
--- a/section3/exercises/hashes.rb
+++ b/section3/exercises/hashes.rb
@@ -1,6 +1,6 @@
# In the below exercises, write code that achieves
# the desired result. To check your work, run this
-# file by entering the following command in your terminal:
+# file by entering the following command in your terminal:
# `ruby section3/exercises/hashes.rb`
# Example: Write code that prints a hash holding grocery store inventory:
@@ -8,24 +8,29 @@
p foods
# Write code that prints a hash holding zoo animal inventory:
-zoo = #YOUR CODE HERE
+zoo = {pinguins: 33, monkeys:27, elephants: 13}#YOUR CODE HERE
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
+puts zoo.keys
-# Write code that prints all of the 'values' of the zoo variable
+# Write code that prints all of the 'values' of the zoo variable
# you created above:
# YOUR CODE HERE
+puts zoo.values
-# Write code that prints the value of the first animal of the zoo variable
+# Write code that prints the value of the first animal of the zoo variable
# you created above:
# YOUR CODE HERE
+puts zoo.values.first
-# 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["lion"] = 1
+puts zoo
#-------------------
@@ -38,17 +43,18 @@
# Declare a variable that stores hash. Each key should be an attribute of an email and each
# value should be some appropriate value for that key. Work to have at least 5 key-value pairs.
-
+email = {"sender" => "Luis", "subject" => "Where are you?", "body" => "I need to talk to you. Please email me!", "signature" => "Love,"}
# 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
-
-# Write code that prints all of the 'values' of the email hash
+puts email.keys
+# Write code that prints all of the 'values' of the email hash
# you created above:
# YOUR CODE HERE
+puts email.values
#-------------------
@@ -64,7 +70,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 +82,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 +96,34 @@
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.
+email = [
+ {
+ 'sender' => "Luis",
+ 'subject' => "Where are you?",
+ 'body' => "I need to talk to you. Please email me!",
+ 'signature' => "Love,"
+ },
+ {
+ 'sender' => "Ana",
+ 'subject' => "I miss you",
+ 'body' => "Hello sister! Let's do zoom today please!",
+ 'signature' => "Kisses,"
+ },
+ {
+ 'sender' => "Karen",
+ 'subject' => "Work tomorrow",
+ 'body' => "I need you to work tomorrow. Please call me",
+ 'signature' => "Thank you,"
+ }
+]
+ puts email
+ puts email[1]
diff --git a/section3/reflection.md b/section3/reflection.md
index cda726fd3..6ba677fc1 100644
--- a/section3/reflection.md
+++ b/section3/reflection.md
@@ -1,17 +1,28 @@
## Section 3 Reflection
1. What are two points from the Growth Mindset article and/or video that either resonated with you, or were brand new to you?
+The article talks about how believing you can grow, can improve your learning process. This resonates with me, because I am sure I can learn coding well. I believe in my abilities and I have clear goals. I am also aware of all the time and dedication I need to be able to learn it well.
+The article also talked about how focusing on the process, helps you reevaluate the approach and strategies. I found myself doing just that while working on mod0 and mod pre-work. Learning coding is very different from college. Time management is something that I am trying to have in mind as I work and learn coding. I usually like to re-read things and practice and play with the examples given. Due to deadlines, I am finding myself reevaluating short term goals, while making plans on going back and re-reading and practicing.
1. In which ways do you currently demonstrate a Growth Mindset? In which ways do you _not_?
+I think I demonstrate a Growth Mindset by believing I can achieve my goals with effort and practice. I also understand that mistakes are needed to learn something well and I do take criticism well and try to improved and correct any errors I might done.
+I don't have yet the problem solving capabilities of a programmer. I plan to work on my Zone of Proximal Development (ZPD) as I keep learning and growing as a programmer. I also have to practice setting measurable, achievable goals and breaking down bigger projects into manageable ones.
1. What is a Hash, and how is it different from an Array?
+A hash is a collection of data with keys and values. Arrays have their elements in order and usually have to be the same data type. In an array you can only use number indexes, while in a hash you can use anything not just numbers.
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 = {treats: 245, food: 100, toys: 125}
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?
+puts states.keys
+puts 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?
+A school list with grades for each one of the students for different subjects. It would be better than an array because with key/values elements, I could narrow down the search when trying to locate a specific item. Also if I don't know the indexes I wouldn't be able to locate the element I want fast.
1. What questions do you still have about hashes?
+I am still trying to wrap my head around hashes. One question I have is whether or not there are different types of hashes?
From 561595055269331e9ae213f24c08107c5a5a9016 Mon Sep 17 00:00:00 2001
From: benistta <92293363+benistta@users.noreply.github.com>
Date: Tue, 2 Nov 2021 21:00:35 -0600
Subject: [PATCH 4/5] Add Section 4 work
---
section2/exercises/ex6_sec2.rb | 2 +-
section4/ex1_sec4.rb | 21 +++++++++++
section4/ex2_sec4.rb | 56 ++++++++++++++++++++++++++++
section4/exercises/burrito.rb | 23 +++++++++++-
section4/exercises/dog.rb | 9 ++++-
section4/exercises/person.rb | 60 +++++++++++++++++++++++++++++-
section4/reflection.md | 67 +++++++++++++++++++++++++++++++++-
7 files changed, 233 insertions(+), 5 deletions(-)
create mode 100644 section4/ex1_sec4.rb
create mode 100644 section4/ex2_sec4.rb
diff --git a/section2/exercises/ex6_sec2.rb b/section2/exercises/ex6_sec2.rb
index a5b2bb104..4b71ba85b 100644
--- a/section2/exercises/ex6_sec2.rb
+++ b/section2/exercises/ex6_sec2.rb
@@ -115,4 +115,4 @@ def divide(a, b)
puts "Is my formula working?"
-#5. I removed the word return and see if the script still works.
+#5. I removed the word return and see if the script still works. It does!
diff --git a/section4/ex1_sec4.rb b/section4/ex1_sec4.rb
new file mode 100644
index 000000000..908e17d08
--- /dev/null
+++ b/section4/ex1_sec4.rb
@@ -0,0 +1,21 @@
+Exercises The Object Model
+1. How do we create an object in Ruby? Give an example of the creation of an object.
+
+ class SmartAnimal
+ class SmartAnimal
+ end
+
+ crow = SmartAnimal.new
+
+
+2. What is a module? What is its purpose? How do we use them with our classes? Create a module for the class you created in exercise 1 and include it properly.
+A module is a collection of reusable behaviors that can be use in other classes. We use them with our classes by using the include method.
+
+ module Communicate
+ end
+
+ class SmartAnimal
+ include Communicate
+end
+
+crow = SmartAnimal.new
diff --git a/section4/ex2_sec4.rb b/section4/ex2_sec4.rb
new file mode 100644
index 000000000..cfed8d4f7
--- /dev/null
+++ b/section4/ex2_sec4.rb
@@ -0,0 +1,56 @@
+#Exercises:
+#1. Create a class called MyCar.
+
+class MyCar
+ attr_accessor :color
+ attr_reader :year
+
+ def initialize(year, color, model)
+ @year = year
+ @color = color
+ @model = model
+ @speed = 0
+ end
+
+ def speeds(number)
+ @speed += number
+ puts "Going too fast!"
+ end
+
+ def brakes(number)
+ @speed -= number
+ puts "Keep slowing down"
+ end
+
+ def speed
+ puts "You are going #{@speed} miles per hour."
+ end
+
+ def shut_car_off
+ @speed = 0
+ puts "Please turn the car off"
+ end
+
+ def spray_paint(color)
+ self.color = color
+ puts "New #{color} color for your car!"
+ end
+end
+
+toyota = MyCar.new(1991, 'gray', 'camri')
+puts toyota.color
+toyota.spray_paint('black')
+puts toyota.color
+#toyota.speeds(80)
+#toyota.speed
+#toyota.brakes(70)
+#toyota.speed
+#toyota.shut_car_off
+#toyota.speed
+#toyota.color = 'green'
+#puts toyota.color
+#puts toyota.year
+
+
+#2. I added an accessor method to the MyCar class to change and view the color of your car.Then added an accessor method that allows me to view, but not modify, the year of the car.
+#3. I create a method called spray_paint that can be called on an object and will modify the color of the car.
diff --git a/section4/exercises/burrito.rb b/section4/exercises/burrito.rb
index 967f68b6c..9d1da3637 100644
--- a/section4/exercises/burrito.rb
+++ b/section4/exercises/burrito.rb
@@ -1,4 +1,4 @@
-# Add the following methods to this burrito class and
+# Add the following methods to this burrito class and
# call the methods below the class:
# 1. add_topping
# 2. remove_topping
@@ -11,9 +11,30 @@ def initialize(protein, base, toppings)
@base = base
@toppings = toppings
end
+
+ def add_topping(another_topping)
+ toppings.push(another_topping)
+ puts "Now you have more toppings: #{toppings}"
+ end
+
+ def remove_topping(undesired_topping)
+ toppings.delete(undesired_topping)
+ puts "Now you have less toppings: #{toppings}"
+ end
+
+ def change_protein(different_protein)
+ @protein = (different_protein)
+ puts "You want #{protein} as your protein? Sure."
+ end
end
dinner = Burrito.new("Beans", "Rice", ["cheese", "salsa", "guacamole"])
p dinner.protein
p dinner.base
p dinner.toppings
+dinner.add_topping("onions")
+dinner.remove_topping("cheese")
+dinner.change_protein("chicken")
+p dinner.protein
+p dinner.base
+p dinner.toppings
diff --git a/section4/exercises/dog.rb b/section4/exercises/dog.rb
index 03221314d..eca07f919 100644
--- a/section4/exercises/dog.rb
+++ b/section4/exercises/dog.rb
@@ -1,5 +1,5 @@
# In the dog class below, write a `play` method that makes
-# the dog hungry. Call that method below the class, and
+# the dog hungry. Call that method below the class, and
# print the dog's hunger status.
class Dog
@@ -19,6 +19,11 @@ def bark
def eat
@hungry = false
end
+
+ def chase_ball
+ @hungry = true
+ p "Fido is so hungry!"
+ end
end
fido = Dog.new("Bernese", "Fido", 4)
@@ -28,3 +33,5 @@ def eat
p fido.hungry
fido.eat
p fido.hungry
+fido.chase_ball
+p fido.hungry
diff --git a/section4/exercises/person.rb b/section4/exercises/person.rb
index 2c26e9570..5a419c33d 100644
--- a/section4/exercises/person.rb
+++ b/section4/exercises/person.rb
@@ -1,5 +1,63 @@
-# Create a person class with at least 2 attributes and 2 behaviors.
+# Create a person class with at least 2 attributes and 2 behaviors.
# Call all person methods below the class and print results
# to the terminal that show the methods in action.
# YOUR CODE HERE
+
+class Person
+ attr_reader :age, :weight, :cook, :work
+ def initialize(age, weight)
+ @age = age
+ @weight = weight
+ @cook = true
+ @work = false
+ end
+
+ def have_birthday(older)
+ @age += older
+ puts "I am now #{age} years old"
+ end
+
+ def no_appetite(lost_weight)
+ @weight -= lost_weight
+ puts "I am never hungry so I lost some weight. Now I weight #{weight} pounds."
+ end
+
+ def cooks
+ @cook = true
+ puts "I love to cook #{cook}"
+ end
+
+ def works
+ @work = false
+ puts "I do currently work #{work}"
+ end
+end
+
+ana = Person.new(21, 130)
+p ana.age
+p ana.weight
+p ana.cook
+p ana.work
+ana.have_birthday(10)
+ana.no_appetite(9)
+ana.cooks
+ana.works
+p ana.age
+p ana.weight
+p ana.cook
+p ana.work
+
+oliver = Person.new(40, 164)
+p oliver.age
+p oliver.weight
+p oliver.cook
+p oliver.work
+oliver.have_birthday(1)
+oliver.no_appetite(2)
+oliver.cooks
+oliver.works
+p oliver.age
+p oliver.weight
+p oliver.cook
+p oliver.work
diff --git a/section4/reflection.md b/section4/reflection.md
index 68b044b00..9a91422c2 100644
--- a/section4/reflection.md
+++ b/section4/reflection.md
@@ -1,22 +1,87 @@
+
## Section 4 Reflection
1. How different did your workflow feel this week, considering we asked you to follow the Pomodoro technique?
+Time management is hard for me since I need to read not once, not twice but sometimes even three times the same information for me to be able to retain the information. I like the idea of having a timer to have a better flow with homework and learning in general. I just have to make sure I still learn what I need to to learn in that time sice I am learning while completing tasks.
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)?
+I was more distracted than expected. I think I just need more practice and getting use to idea of having a timer. I found that it added more pressure and I found myself not being able to focus very well. The more I tried it though, the better it got.
1. In your own words, what is a Class?
+A Class is like a blueprint of an object. It defines its attributes and methods.
1. What is an attribute of a Class?
+An attribute of a Class is a specific property of an object. Is the information the object holds.
1. What is behavior of a Class?
+Behavior of a lass tells us how the Class will react. It is what an object is capable of doing.
1. In the space below, create a Dog class with at least 2 attributes and 2 behaviors:
```rb
+class CuteDog
+ attr_reader :name, :weight, :playful, :loud
+
+ def initialize(name, weight)
+ @name = name
+ @weight = weight
+ @playful = false
+ @loud = true
+ end
+
+ def older
+ @age += 10
+ puts "Simba is now #{age} old"
+ end
+
+ def bigger(weights_more)
+ @weight += weights_more
+ puts "The older he gets the bigger Simba gets. Last year he was weigthing #{weight} pounds"
+ end
+
+ def smaller(weights_less)
+ @weight -= weights_less
+ puts "After year 12, Simba started getting thiner, now he is #{weight} punds"
+ end
+ def barks
+ @loud = true
+ puts "Simba's bark is very loud #{loud}"
+ end
+
+ def plays
+ @playful = false
+ puts "Simba likes to play #{playful} "
+ end
+end
+
+simba = CuteDog.new("Simba", 70)
+p simba.name
+p simba.weight
+p simba.playful
+p simba.loud
+simba.bigger(10)
+simba.smaller(19)
+simba.plays
+simba.barks
+p simba.name
+p simba.weight
+p simba.playful
+p simba.loud
```
1. How do you create an instance of a class?
+By calling the 'new' method on the class. Then is stored in a variable.
+
+1. What questions do you still have about classes in Ruby?
+I do have many questions but I am hoping the more I practice the more I will understand the basic questions. I am still trying to understand for example if there are other types of classes in Ruby?
+
+- Have the time estimates matched up with your experience?
+I definitely spent more time than I was expecting. I am the kind of learner that has to re-read things and have to practice over and over to learn well.
+
+- When you sit down to start working, do you have a clear goal of what you want to accomplish and in how much time? If so, how aligned is that to what actually happens?
+I do have a clear goal I want to accomplish when working on something. With coding however since I am just starting to learn the basics, it takes me longer than expected. I believe the more comfortable I get with the basics, the more I will be able to follow my time limits and goals.
-1. What questions do you still have about classes in Ruby?
\ No newline at end of file
+- How do you work best - in 2 hour blocks, 4 hour blocks, etc? Do you take breaks regularly? Do you have a system to hold yourself accountable to taking breaks?
+I work best in smaller blocks of time. I do try to takes breaks as soon as start feeling I am not paying as much attention, or when I have to read over and over the same thing to understand it. I am actually looking for an alternative to a timer to take breaks. For now, I am using a timer.
From 03cdd2d1164691bfd9348c03539d73bfa8be571b Mon Sep 17 00:00:00 2001
From: benistta <92293363+benistta@users.noreply.github.com>
Date: Wed, 3 Nov 2021 13:50:06 -0600
Subject: [PATCH 5/5] Add final_prep
---
final_prep/README.md | 40 ++++++------
final_prep/annotations.rb | 33 ++++++++--
final_prep/mod_zero_hero.rb | 125 ++++++++++++++++++++++++++++--------
3 files changed, 147 insertions(+), 51 deletions(-)
diff --git a/final_prep/README.md b/final_prep/README.md
index 22bfb5154..e17ecc45a 100644
--- a/final_prep/README.md
+++ b/final_prep/README.md
@@ -3,13 +3,13 @@ Congrats on making it to the Mod 0 Final Prep! Complete the final exercises belo
### Final Technical Prep
-You've learned a ton about some of the core foundations of Javascript! Show us how far you've come by completing the following exercises! You will be using your work from these exercises in your first day of Mod 1!
+You've learned a ton about some of the core foundations of Javascript! Show us how far you've come by completing the following exercises! You will be using your work from these exercises in your first day of Mod 1!
-- [ ] Complete the [Mod Zero Hero Challenge](./mod_zero_hero.rb)
-- [ ] Complete the [Annotation Challenge](./annotations.rb)
+- [ X] Complete the [Mod Zero Hero Challenge](./mod_zero_hero.rb)
+- [ X] Complete the [Annotation Challenge](./annotations.rb)
### Refactor Previous Work
-You've learned A LOT over the last few weeks as it relates to technical content - chances are, you probably have some code from your previous exercises that is either sloppy, incorrect, poorly named, etc. Before starting Mod 1, we want you to `refactor` your code - which is the process of adjusting or improving your code for readability and accuracy.
+You've learned A LOT over the last few weeks as it relates to technical content - chances are, you probably have some code from your previous exercises that is either sloppy, incorrect, poorly named, etc. Before starting Mod 1, we want you to `refactor` your code - which is the process of adjusting or improving your code for readability and accuracy.
Some things to consider as you refactor include...
- Are my variable names easy to understand/convey the data type they are assigned to?
@@ -19,37 +19,41 @@ Some things to consider as you refactor include...
Take your time as you go back and refactor your exercises from each section. We've included a handy checklist for you to go through below.
-- [ ] I have refactored my `section1` exercises to the best of my ability
-- [ ] I have refactored my `section2` exercises to the best of my ability
-- [ ] I have refactored my `section3` exercises to the best of my ability
-- [ ] I have refactored my `section4` exercises to the best of my ability
+- [ X] I have refactored my `section1` exercises to the best of my ability
+- [ X] I have refactored my `section2` exercises to the best of my ability
+- [ X] I have refactored my `section3` exercises to the best of my ability
+- [ X] I have refactored my `section4` exercises to the best of my ability
### Time Management Prep
In Mod 0 you've learned about different techniques for managing your time at Turing. Please create a calendar for your **first 3 weeks of Mod 1**. Feel free to make your calendar fit your style, but we suggest that your calendar should include the following:
-- [ ] Standard M1 class schedule (see M1 calendar [here](https://backend.turing.io/module1/)
-- [ ] Study/Project work time
-- [ ] Health + Wellness
+- [ X] Standard M1 class schedule (see M1 calendar [here](https://backend.turing.io/module1/)
+- [ X] Study/Project work time
+- [ X] Health + Wellness
When you are finished, add screenshots of your calendar so we can provide feedback if needed!
- `Add Week 1 Screenshot Here`
- `Add Week 2 Screenshot Here`
- `Add Week 3 Screenshot Here`
+
+
+>
### Mentorship Prep
Mentorship is an integral part of the Turing experience and will help jumpstart your technical career. In order to get your mentor relationship started on the right foot, please complete the following deliverables:
-- [ ] Complete the [Mentorship DTR Prep](https://gist.github.com/ericweissman/51965bdcbf42970d43d817818bfaef3c)
- - [ ] Add link to your gist here:
+- [ X] Complete the [Mentorship DTR Prep](https://gist.github.com/ericweissman/51965bdcbf42970d43d817818bfaef3c)
+ - [ X] Add link to your gist here:[My Mentee DTR prep](https://gist.github.com/benistta/f03e977c2a12d1d77cdecdeb0e265937)
### Lesson Prep
You've learned a lot about how to take strong notes during Mod 0. Show us your skills while you learn how to pre-teach content for your first lesson in Mod 1!
-- [ ] Complete the [Pre Teaching Practice exercise](https://gist.github.com/ericweissman/0036e8fe272c02bd6d4bb14f42fd2f79) gist
- - [ ] Add a link to your gist here:
+- [ X] Complete the [Pre Teaching Practice exercise](https://gist.github.com/ericweissman/0036e8fe272c02bd6d4bb14f42fd2f79) gist
+ - [ X] Add a link to your gist here:[My Pre Teaching Practice exercises](https://gist.github.com/benistta/6aadae3582d8848990939a2e329eae29)
### Group Work Prep
As part of Turing's project-based learning approach, you will often be working in pairs or larger groups. In order to set yourself (and your team) up for success, it is important to ensure you are prepared to be an equitable contributor and teammate.
-- [ ] Complete the [DTR Guiding Questions](https://gist.github.com/ericweissman/c56f3a98cdce761808c21d498a52f5c6)
- - [ ] Add a link to your gist here:
+- [ X] Complete the [DTR Guiding Questions](https://gist.github.com/ericweissman/c56f3a98cdce761808c21d498a52f5c6)
+ - [ X] Add a link to your gist here:[My Guiding Questions](https://gist.github.com/benistta/578fee471b980655ca24ed858c5e9715)
## 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 +90,4 @@ What is your plan and how are you going to hold yourself to it? Specifically...
- What personal items/events are important to you during this time? How are you going to make sure those are not neglected? (Hint, block time on the calendar for them!)
## Extensions
-Check out our thoughts on [extension activities](https://mod0.turing.io/prework/extensions) if you find yourself with some extra time before starting Mod 1!
\ No newline at end of file
+Check out our thoughts on [extension activities](https://mod0.turing.io/prework/extensions) if you find yourself with some extra time before starting Mod 1!
diff --git a/final_prep/annotations.rb b/final_prep/annotations.rb
index 8b938706c..4c3eb240c 100644
--- a/final_prep/annotations.rb
+++ b/final_prep/annotations.rb
@@ -3,11 +3,15 @@
# Use the # to create a new comment
# Build a Bear
-
+# Create a function called build_a_bear that takes 6 arguments: name, age, fur, clothes, special_power
def build_a_bear(name, age, fur, clothes, special_power)
+ #greeting should be a string that has the name argument
greeting = "Hey partner! My name is #{name} - will you be my friend?!"
+ #demographics should an array that has elements: name and age
demographics = [name, age]
+ #power_saying should be a string that includes the special_power argument
power_saying = "Did you know that I can #{special_power}?"
+ #built_bearshould be a hash with elements: basic_info, clothes, exterior, cost, sayings, is_cuddly
built_bear = {
'basic_info' => demographics,
'clothes' => clothes,
@@ -16,28 +20,47 @@ def build_a_bear(name, age, fur, clothes, special_power)
'sayings' => [greeting, power_saying, "Goodnight my friend!"],
'is_cuddly' => true,
}
+ #return build_bear
return built_bear
+ #end
end
-
+#test cases:
+#build_a_bear('Fluffy', 4, 'brown', ['pants', 'jorts', 'tanktop'], 'give you nightmares')
build_a_bear('Fluffy', 4, 'brown', ['pants', 'jorts', 'tanktop'], 'give you nightmares')
+#build_a_bear('Sleepy', 2, 'purple', ['pajamas', 'sleeping cap'], 'sleeping in')
build_a_bear('Sleepy', 2, 'purple', ['pajamas', 'sleeping cap'], 'sleeping in')
# FizzBuzz
-
+#Create a function called fizzbuzz that takes 3 argument: num_1, num_2, range
def fizzbuzz(num_1, num_2, range)
+ #loop with .each do instead of for loop
(1..range).each do |i|
+ #Use modulo operator to get the remainder of the division i on num-1
+ #if i modulo num_1 triple equals 0 AND i modulo num_2 triple equals 0
if i % num_1 === 0 && i % num_2 === 0
+ #print "fizzbuzz"
puts 'fizzbuzz'
+ #else if i modulo num_1 triple equals 0
elsif i % num_1 === 0
+ #print "fizz"
puts 'fizz'
+ #else if i modulo num_2 triple equals 0
elsif i % num_2 === 0
+ #print "buzz"
puts 'buzz'
+ #otherwise
else
+ #print i
puts i
+ #end
end
+ #end
end
+ #end
end
-
+#test cases
+#fizzbuzz(3, 5, 100)
fizzbuzz(3, 5, 100)
-fizzbuzz(5, 8, 400)
\ No newline at end of file
+#fizzbuzz(5, 8, 400)
+fizzbuzz(5, 8, 400)
diff --git a/final_prep/mod_zero_hero.rb b/final_prep/mod_zero_hero.rb
index 35eb2cdac..d666f3956 100644
--- a/final_prep/mod_zero_hero.rb
+++ b/final_prep/mod_zero_hero.rb
@@ -1,52 +1,72 @@
# Challenge - See if you can follow the instructions and complete the exercise in under 30 minutes!
# Declare two variables - hero_name AND special_ability - set to strings
-
+hero_name = "Learny"
+special_ability = "Instant learning"
# Declare two variables - greeting AND catchphrase
# greeting should be assigned to a string that uses interpolation to include the hero_name
+greeting = " Hello I am #{hero_name}!"
# catchphrase should be assigned to a string that uses interpolation to include the special_ability
-
+catchphrase = "#{special_ability} will save the world! "
# Declare two variables - power AND energy - set to integers
-
+power = 100
+energy = 90
# Declare two variables - full_power AND full_energy
# full_power should multiply your current power by 500
+full_power = power * 500
# full_energy should add 150 to your current energy
-
+full_energy = energy + 150
# Declare two variables - is_human and identity_concealed - assigned to booleans
-
+is_human = true
+identity_concealed = false
# Declare two variables - arch_enemies AND sidekicks
# arch_enemies should be an array of at least 3 different enemy strings
+arch_enemies = ['Dum', 'Idot', 'Lem']
# sidekicks should be an array of at least 3 different sidekick strings
-
+sidekicks = ['Superman', 'Batman', 'Wonderwoman']
# Print the first sidekick to your terminal
-
+p sidekicks[0]
# Print the last arch_enemy to the terminal
-
+p arch_enemies[2]
# Write some code to add a new arch_enemy to the arch_enemies array
-
+arch_enemies << 'Stoop'
# Print the arch_enemies array to terminal to ensure you added a new arch_enemey
-
+p arch_enemies
# Remove the first sidekick from the sidekicks array
-
+sidekicks.shift
# Print the sidekicks array to terminal to ensure you added a new sidekick
-
+p 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)
+ danger = 0
+ announcement = 'I just saved the day!'
+ excuse = 'I will let Superman have a chance to save the day today.'
+ #puts "How dangerous is it?"
+ #danger_measurement = $stdin.gets.chomp.to_i
# 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.
+ if danger > 50
+ puts "'I just saved the day!'"
+ elsif danger >= 10 && danger <= 50
+ puts "'I will let Superman have a chance to save the day today.'"
+ else
+ puts "Meh. Hard pass."
+ end
+end
#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.'
-# assess_situation(99, announcement, excuse) > Should print - 'I think I forgot to lock up my 1992 Toyota Coralla. Be right back.'
-#assess_situation(21, announcement, excuse) > should print - 'Never fear, the Courageous Curly Bracket is here!'
-#assess_situation(3, announcement, excuse) > should print - "Meh. Hard pass."
+#announcement = 'I just saved the day!'
+#excuse = 'I will let Superman have a chance to save the day today.'
+assess_situation(99, announcement, excuse) #> Should print - 'I think I forgot to lock up my 1992 Toyota Coralla. Be right back.'
+assess_situation(21, announcement, excuse) #> should print - 'Never fear, the Courageous Curly Bracket is here!'
+assess_situation(3, announcement, excuse) #> should print - "Meh. Hard pass."
# Declare a new variable - scary_monster - assigned to an hash with the following key/values
# - name (string)
@@ -56,29 +76,78 @@
# - luckyNumbers (array)
# - address (hash with following key/values: number , street , state, zip)
+scary_monster = {
+ "name" => '',
+ "smell" => '',
+ "weight" => 400,
+ "cities_destroyed" => ['Paris', 'Milan', 'Texas'],
+ "lucky_numbers" => [1, 2, 3, 4],
+ "address" => {
+ "number" => 10,
+ "street" => 'King',
+ "state" => 'CO',
+ "zip" => 80301
+ }
+}
+
# 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, power_level, energy_level)
+ @name = name
+ @super_power = super_power
+ @age = age
+ @arch_nemesis = arch_nemesis
+ @power_level = power_level
+ @energy_level = energy_level
+ 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
-
+ def say_name
+ puts "His name is #{name}"
+ end
+
+ def maximize_energy
+ @energy_level = 1000
+ end
+
+ def gain_power(number)
+ @power_level += number
+ puts "He gained power to #{power_level}"
+ end
+end
# - Create 2 instances of your SuperHero class
-
-
+learny = SuperHero.new("learny", "Instant learning", 50, 10, 20)
+p learny.name
+p learny.super_power
+p learny.age
+p learny.power_level
+p learny.energy_level
+learny.say_name
+learny.maximize_energy
+learny.gain_power(10)
+p learny.name
+p learny.super_power
+p learny.age
+p learny.power_level
+p learny.energy_level
# Reflection
# What parts were most difficult about this exerise?
-
+#Remembering all the technical words and syntax was very difficult.
# What parts felt most comfortable to you?
-
+#The firsdt part of the exercise was the most easiest to me.
# What skills do you need to continue to practice before starting Mod 1?
-
+#I need to practice, practice and practice! I defenitly need to get more comfortable qith the wording and understanding the meaning of each line of pseudocode.