Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joe Mecha #427

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Binary file added .DS_Store
Binary file not shown.
Binary file added day_1/.DS_Store
Binary file not shown.
14 changes: 7 additions & 7 deletions day_1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ This will open the day_1 directory in Atom. You should be able to see the direct

1. Check off the items below as you complete the steps you just read for each lesson. ***Remember to create a file containing your work for each lesson!***

- [ ] [A Good First Program](https://learnrubythehardway.org/book/ex1.html)
- [**X**] [A Good First Program](https://learnrubythehardway.org/book/ex1.html)

- [ ] [Comments in Code](https://learnrubythehardway.org/book/ex2.html)
- [**X**] [Comments in Code](https://learnrubythehardway.org/book/ex2.html)

- [ ] [Numbers and Math](https://learnrubythehardway.org/book/ex3.html)
- [**X**] [Numbers and Math](https://learnrubythehardway.org/book/ex3.html)

- [ ] [Variables and Names](https://learnrubythehardway.org/book/ex4.html)
- [**X**] [Variables and Names](https://learnrubythehardway.org/book/ex4.html)

- [ ] [Strings](https://learnrubythehardway.org/book/ex5.html)
- [**X**] [Strings](https://learnrubythehardway.org/book/ex5.html)

- [ ] [More Strings](https://learnrubythehardway.org/book/ex6.html)
- [**X** ] [More Strings](https://learnrubythehardway.org/book/ex6.html)

- [ ] [Asking for Input](https://learnrubythehardway.org/book/ex11.html)
- [**X** ] [Asking for Input](https://learnrubythehardway.org/book/ex11.html)

- [ ] Have you created 7 `ex.rb` files with your code in them?

Expand Down
7 changes: 7 additions & 0 deletions day_1/exercises/ex1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
puts "Hello World!"
puts "Hello Again"
puts "I like typing this."
puts "This is fun."
puts "Yay! Printing."
puts "I'd much rather you 'not'."
puts 'I "said" do not touch this.'
9 changes: 9 additions & 0 deletions day_1/exercises/ex2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# A comment, this is so you can read your program later.
# Anything after the # is ignored by ruby.

puts "I could have code like this." # and the comment after is ignored.

# You can also use a comment to "disable" or comment out a piece of code.
# puts "This won't run."

puts "This will run."
29 changes: 29 additions & 0 deletions day_1/exercises/ex3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
puts "I will now count my chickens:"

# calculates 25 plus the result of 30/6 (5)
puts "Hens #{25.0 + 30 / 6}"
# calculates 100 minus the remainder of
# 75/4 (3) = 97
puts "Roosters #{100.0 - 25 * 3 % 4}"

puts "Now I will count the eggs:"

# Follow the order of operations
puts 3.0 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6

puts "Is it true that 3 + 2 < 5 - 7?"

# Returns boolean result of 5 < -2 (false)
puts 3.0 + 2 < 5 - 7

# #{} allows calculations to be contained within strings in ruby
puts "What is 3 + 2? #{3.0 + 2}"
puts "What is 5 - 7? #{5.0 - 7}"

puts "Oh, that's why it's false."

puts "How about some more."

puts "Is it greater? #{5.0 > -2}"
puts "Is it greater or equal? #{5.0 >= -2}"
puts "Is it less or equal? #{5.0 <= -2}"
23 changes: 23 additions & 0 deletions day_1/exercises/ex4.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# assign values to Variables
# integer
cars = 100
# integer, these will be full cars with 3 passengers sharing the backseat
space_in_a_car = 4
# integer
drivers = 30
# integer
passengers = 90
# integer
cars_not_driven = cars - drivers
# integer, variable is easier to understand and use in context than drivers
cars_driven = drivers
carpool_capacity = cars_driven * space_in_a_car
average_passengers_per_car = passengers / cars_driven

# Print strings with values using #{variable_name}

puts "There are #{cars} available."
puts "There are only #{drivers} drivers available."
puts "There will be #{cars_not_driven} empty cars today."
puts "We can transport #{carpool_capacity} people today."
puts "We need to put about #{average_passengers_per_car} in each car."
23 changes: 23 additions & 0 deletions day_1/exercises/ex5.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# More practice with embedding variables in strings using #{}

my_name = 'Zed A. Shaw'
my_age = 35 # not true now
my_height = 74 # inches
my_weight = 180 # pounds
my_eyes = 'blue'
my_teeth = 'white'
my_hair = 'brown'
my_weight_in_kg = my_weight / 2.20462
my_height_in_cm = my_height * 2.54

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 et it exactly right
puts "If I add #{my_age}, #{my_height}, and #{my_weight} I get #{my_age + my_height + my_weight}."

puts "Zed's weight in kg is #{my_weight_in_kg.round(1)}kg and his height in cm is #{my_height_in_cm.round(1)}cm."
23 changes: 23 additions & 0 deletions day_1/exercises/ex6.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Exercise to practice working with strings

types_of_people = 10
x = "There are #{types_of_people} types of people."
binary = "binary"
do_not = "don't"
y = "Those who know #{binary} and those who #{do_not}."

puts x
puts y

puts "I said: #{x}."
puts "I also said: '#{y}'."

hilarious = false
joke_evaluation = "Isn't that joke so funny?! #{hilarious}"

puts joke_evaluation

w = "This is the left side of..."
e = "a string with a right side."

puts w + e
12 changes: 12 additions & 0 deletions day_1/exercises/ex7.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This is Exercise 11 in Ruby the Hard Way

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."

# Use gets.chomp.to_i to get a string from a user and convert to integer
6 changes: 3 additions & 3 deletions day_1/exercises/interpolation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
p "The #{team} are #{name}'s favorite Quidditch team"

# Write code that uses the variables below to form a string that reads
# "The quick red fox jumped over the lazy brown dog":
# "The quick red fox jumped over the lazy brown dog.":
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}!"
7 changes: 5 additions & 2 deletions day_1/exercises/loops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@

# 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
sally = "She sells seashells down by the seashore"
10.times do
puts sally
end
9 changes: 5 additions & 4 deletions day_1/exercises/numbers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
# `ruby day_1/exercises/numbers.rb`

# Example: Write code that prints the result of the sum of 2 and 2:
p 2 + 2
#p 2 + 2

# Write code that prints the result of 7 subtracted from 83:
p #YOUR CODE HERE

puts "7 subtracted from 83 is #{83 - 7}." #YOUR CODE HERE

# Write code that prints the result of 6 multiplied by 53:
# YOUR CODE HERE
puts "6 times 53 is #{6 * 53}."

# Write code that prints the result of the modulo of 10 into 54:
# YOUR CODE HERE
puts "The remainder of 54 divided by 10 (modulo) is #{54 % 10}."
4 changes: 2 additions & 2 deletions day_1/exercises/strings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
p "Alan Turing"

# Write code that prints `Welcome to Turing!` to the terminal:
p #YOUR CODE HERE
puts "Welcome to Turing!" #YOUR CODE HERE

# Write code that prints `99 bottles of pop on the wall...` to the terminal:
# YOUR CODE HERE
puts "99 bottles of soda on the wall..."
15 changes: 8 additions & 7 deletions day_1/exercises/variables.rb
Original file line number Diff line number Diff line change
@@ -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 day_1/exercises/variables.rb`

# Example: Write code that saves your name to a variable and
Expand All @@ -11,19 +11,20 @@
# 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
dobby_warning = "Harry Potter must not return to Hogwarts."
puts dobby_warning

# Write code that adds 2 to the `students` variable and
# prints the result:
students = 22
# YOUR CODE HERE
p students
students = students + 2
puts students

# Write code that subracts 2 from the `students` variable and
# prints the result:
# YOUR CODE HERE
p students
students = students - 2
puts students
26 changes: 19 additions & 7 deletions day_1/questions.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
## Day 1 Questions

1. How would you print the string `"Hello World!"` to the terminal?

'''ruby
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?

An integer is a whole number (1, 5, -3) and a float contains a decimal (1.5, 5.3, 0.01)
1. In the space below, create a variable `animal` that holds the string `"zebra"`

'''ruby
animal = "zebra"
'''
1. How would you print the string `"zebra"` using the variable that you created above?

'''ruby
puts animal
'''
1. What is interpolation? Use interpolation to print a sentence using the variable `animal`.

Interpolation in ruby is including results of code within a string, such as the results of variables and calculations.
'''ruby
puts "Can you draw a #{animal}?"
'''
(I tried to look up a way to check if the first letter of the string was a consonant or vowel to make an if/else for the article a/an, but needed to move on before solving)
1. What method is used to get input from a user?

gets.chomp
1. Name and describe two common string methods:
* .length returns number of characters in a string
* .split breaks a string into parts and puts into an array; can also take an argument
Binary file added day_2/.DS_Store
Binary file not shown.
30 changes: 30 additions & 0 deletions day_2/array_methods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
### Common Array Methods
###### Mod 1 Pre-work, Day 2

.sort -- if elements are strings, returns new alphabetized array

.each -- iterates through each element
```ruby
animals = ["cat", "dog", "bird", "snake"]
animals.each {|x| print x, " | "}
```
```
cat | dog | bird | snake
```

.join -- connects string elements into one strong

.include?() -- find if an array contains an element

.first -- returns first element
.last -- returns last element

.length .count .size -- returns number of elements

.insert(position, element(s)) -- inserts one or more elements at the specified position

.unshift -- add to the beginning of an array

.pop -- removes and returns last element

.uniq -- removes duplicates from array
25 changes: 14 additions & 11 deletions day_2/exercises/arrays.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,38 @@
# Example: Write code that stores an array in a variable,
# then prints that array:
animals = ["Zebra", "Giraffe", "Elephant"]
p animals
puts animals

# Write code that stores an array of states in a variable,
# then prints that array:
states = #YOUR CODE HERE
p states
states = ["Arizona", "Colorado", "Tennessee", "Wisconsin"]
puts states

# Write code that stores an array of foods in a variable,
# then prints that array:
# YOUR CODE HERE
foods = ["rice", "soba", "udon", "ramen"]
puts foods

# Example: Write code that prints the number of elements
# in your above array of animals:
p animals.count
puts animals.count

# Write code that prints the number of elements
# in your above array of foods:
# YOUR CODE HERE
puts foods.size

# Write code that prints "Zebra" from your animals array:
# YOUR CODE HERE
puts animals[0]
#puts animals.first

# Write code that prints the last item of your foods array:
# YOUR CODE HERE
puts foods.last
#puts foods[-1]

# Write code that adds "lion" to your animals array
# and prints the result (Hint- use a method):
# YOUR CODE HERE
animals << "lion"
puts animals.last

# Write code that removes the last element from your foods array
# and prints the result (Hint- use a method):
# YOUR CODE HERE
foods.pop
Loading