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

Kevin Nguyen #437

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions day_1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ 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?
- [X] Have you created 7 `ex.rb` files with your code in them?

1. Work through the [Strings](http://tutorials.jumpstartlab.com/projects/ruby_in_100_minutes.html#3.-strings) and [Numbers](http://tutorials.jumpstartlab.com/projects/ruby_in_100_minutes.html#5.-numbers) sections from Ruby in 100 Minutes. For each of these sections, open an `irb` session by typing `irb` into your terminal and type in the code snippets provided.

Expand Down
8 changes: 8 additions & 0 deletions day_1/ex1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
puts "Hello World!"
puts "Hello Again"
puts "I like typing this."
puts "This is fun."
puts "Yay! Printing."
puts "I'd much rather you 'not'."
puts 'I "said" do not touch this.'
#mod for new commit
9 changes: 9 additions & 0 deletions day_1/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."

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

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

puts "Hens #{25.0 + 30 /6}"
puts "Rooster #{100.0 - 25 * 3 % 4}"

puts "Now I will count the eggs:"

puts 3.0 + 2 + 1 - 5 + 4 % 2 - 1 /4 + 6
puts "Is it true that 3 + 2 < 5 - 7?"

puts 3 + 2 < 5 - 7

puts "What is 3 + 2? #{3.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 > -2}"
puts "Is it greater or equal? #{5 >= -2}"
puts "Is it less or equal? #{5 <= -2}"
21 changes: 21 additions & 0 deletions day_1/ex4.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cars = 100
space_in_a_car = 4.0
drivers = 30
passengers = 90
cars_not_driven = cars - drivers
cars_driven = drivers
carpool_capacity = cars_driven * space_in_a_car
average_passengers_per_car = passengers / cars_driven


puts "There are #{cars} cars available."
puts "There are only #{drivers} drivers available."
puts "There will be #{cars_not_driven} empty cars today."
puts "We can transport #{carpool_capacity} people today."
puts "We have #{passengers} to carpool today."
puts "We need to put about #{average_passengers_per_car} in each car."

#Study Drills ?: The error says that on line 14 in the code, the variables
#'carpool_capacity' was not defined before its use.
#1. '.0' making the 4 a float is not necessary bc there will not be a decimal
# or tenth of a person.
19 changes: 19 additions & 0 deletions day_1/ex5.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name = 'Zed A. Shaw'
age = 35 #not a lie in 2009
height = 74 # inches
ht_cm = height * 2.54 # centimeters
weight = 180 # lbs
wt_kg = weight * 0.45 # kilograms
eyes = 'Blue'
teeth = 'White'
hair = 'Brown'

puts "Let's talk about #{name}."
puts "He's #{height} inches tall, or #{ht_cm} centimeters."
puts "He's #{weight} pounds or #{wt_kg} kg 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}."
37 changes: 37 additions & 0 deletions day_1/ex6.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Define first variable
types_of_people = 10
# Defines string wtih first variable inserted
x = "There are #{types_of_people} types of people."

# Defines a third variable
binary = "binary"
# Defines a fourth variable
do_not = "don't"
# Defines string wtih two variables inserted
y = "Those who know #{binary} and those who #{do_not}."

# Prints first string
puts x
# Prints second string
puts y

# Prints first string insterted into a string
puts "I said: #{x}."
# Prints second string insterted into a string
puts "I also said: #{y}."

# Define a boolean variable 'hilarious'
hilarious = false
# Defines another string, that has the boolean variable insterted
joke_evaluation = "Isn't that joke so funny?! #{hilarious}"

# Prints the previous string
puts joke_evaluation

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

# Prints w and e string in sequence
puts w + e
10 changes: 10 additions & 0 deletions day_1/ex7.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
print "How old are you? "
age = gets.to_i
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."
ten_years = age + 10
p "You'll be #{ten_years} in a decade, wow."
38 changes: 38 additions & 0 deletions day_1/exercise7.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Outputs a string
puts "Mary had a little lamb"
# Outputs a string with substring insterted
puts "Its fleece was white as #{'snow'}."
# Outputs 10 consecutive '.'
puts "." * 10 # what'd that do?

# Defines a variable
end1 = "C"
# Defines a variable
end2 = "h"
# Defines a variable
end3 = "e"
# Defines a variable
end4 = "e"
# Defines a variable
end5 = "s"
# Defines a variable
end6 = "e"
# Defines a variable
end7 = "B"
# Defines a variable
end8 = "u"
# Defines a variable
end9 = "r"
# Defines a variable
end10 = "g"
# Defines a variable
end11 = "e"
# Defines a variable
end12 = "r"

# watch that pring vs. puts on this line what's it do?
# Outputs first 6 strings of letters consecutively, w/o a line break
print end1 + end2 + end3 + end4 + end5 + end6
# Outputs the next 6 string of letters after the previous
puts end7 + end8 + end9 + end10 + end11 + end12
#mod for 2nd commit
4 changes: 2 additions & 2 deletions day_1/exercises/interpolation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
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!":
slow_poke = "tortoise"
speedy = "hare"

# YOUR CODE HERE
p "In a predictable result, the #{slow_poke} beat the #{speedy}!" # YOUR CODE HERE
8 changes: 5 additions & 3 deletions day_1/exercises/loops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

# Example: Write code that prints your name five times:
5.times do
p "Hermione Granger"
p "Kevin Nguyen rules!"
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 # YOUR CODE HERE
6 changes: 3 additions & 3 deletions day_1/exercises/numbers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
p 2 + 2

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

# Write code that prints the result of 6 multiplied by 53:
# YOUR CODE HERE
p 6 * 53 #YOUR CODE HERE

# Write code that prints the result of the modulo of 10 into 54:
# YOUR CODE HERE
p 10.modulo(54) # YOUR CODE HERE
6 changes: 3 additions & 3 deletions day_1/exercises/strings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
# `ruby day_1/exercises/strings.rb`

# Example: Write code that prints your name to the terminal:
p "Alan Turing"
p "Kevin Nguyen" #"Alan Turing"

# 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
p "99 bottles of pop on the wall..." # YOUR CODE HERE
11 changes: 6 additions & 5 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
p house_elf # YOUR CODE HERE

# 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
what = "Harry Potter must not return to Hogwarts!"
p what # YOUR CODE HERE

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

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

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

1. What character is used to indicate comments in a ruby file?
`1.2 What character is used to indicate comments in a ruby file?`
#

1. Explain the difference between an integer and a float?
`1.3 Explain the difference between an integer and a float?`
Decimal point and decimal value

1. In the space below, create a variable `animal` that holds the string `"zebra"`
`1.4 In the space below, create a variable `animal` that holds the string `"zebra"`
animal = 'zebra'

1. How would you print the string `"zebra"` using the variable that you created above?
`1.5 How would you print the string `"zebra"` using the variable that you created above?`
puts animal

1. What is interpolation? Use interpolation to print a sentence using the variable `animal`.
`1.6 What is interpolation? Use interpolation to print a sentence using the variable `animal`.`
puts "The best creature is the #{animal}."

1. What method is used to get input from a user?
`1.7 What method is used to get input from a user?`
answer = get.chomp

1. Name and describe two common string methods:
`1.8 Name and describe two common string methods:'
.length and .split
17 changes: 17 additions & 0 deletions day_2/array_methods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'.sort': sorts arrays of strings alphabetically and numbers in ascending order.

'.each': .each {|a| print a -= 10, " "} array iterator that specifies and action to be done for each array element.

'.join': or .join("-") returns all the element joined into one string with no space or a specified separator in between

'.index': .index("a") returns the position (ie 0,1,2) for the first element that matches, or "nil" if it is not present.

'.include?': .include?("a") searches if an element is present and returns "true" or "false"

'.collect': .collect {|a| a + "!"} returns new values of each element after a specified action.

'.first': or .first(2) returns the first or first number of elements in an array.

'.last': or .last(2) returns the last or last number of elements in an array.

'.shuffle': or .shuffle! randomizes order of elements temporarily or permanently with "!"
27 changes: 17 additions & 10 deletions day_2/exercises/arrays.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,39 @@
p animals

# Write code that stores an array of states in a variable,
# then prints that array:
states = #YOUR CODE HERE
# then prints that array: #YOUR CODE HERE-
states = [ "Florida", "Texas", "Idaho", "Utah"]
p states

# Write code that stores an array of foods in a variable,
# then prints that array:
# YOUR CODE HERE
# then prints that array: # YOUR CODE HERE-
foods = [ "Burgers", "Fries", "Shakes"]
p foods

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

# Write code that prints the number of elements
# in your above array of foods:
# YOUR CODE HERE
# in your above array of foods: # YOUR CODE HERE-
p foods.count

# Write code that prints "Zebra" from your animals array:
# YOUR CODE HERE
# YOUR CODE HERE-
p animals[0]

# Write code that prints the last item of your foods array:
# YOUR CODE HERE
# YOUR CODE HERE-
p foods.last

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

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