Skip to content

Instantly share code, notes, and snippets.

@marinalaguerre20
Created July 31, 2015 17:17
Show Gist options
  • Save marinalaguerre20/33d68a67e1c11942b06e to your computer and use it in GitHub Desktop.
Save marinalaguerre20/33d68a67e1c11942b06e to your computer and use it in GitHub Desktop.
# # create a function that takes the string and adds the phrase
# "only in America!" to the end of it.
puts "Exercise 1: Please enter you phrase"
phrase = gets.chomp
def add(phrase)
phrase + " only in America"
end
puts add(phrase)
# Create a function to find the maximum value in an
# array of numbers. For instance: [100,10,-1000]
def Max(numbers)
max_value = numbers.sort.last
puts "Based on your entry, you max number is #{max_value}"
end
puts Max
puts "please enter your numbers"
def findmax(numbers)
numbers = gets.chomp
numbers = numbers.split(',')
biggest = 0
numbers.each do |n|
number = n.to_i
if number > biggest
biggest = number
end
end
# numbers.sort.last
end
puts findmax(numbers)
# Create a function that takes two arguments -
# Inside of the function, combine the arrays using
# the items from the first array as keys and the
# second array as values.
puts "Please enter you fruits with comma between them"
fruits = gets.chomp
puts "your fruits are: #{fruits}."
puts " "
puts "Now please enter your color for each fruit in the same order also with commas between"
colors = gets.chomp
array_one = fruits.split(",")
array_two = colors.split(",")
def combine(a, b)
puts myHash = {a[0] => b[0], a[1] => b[1], a[2] => b[2]}
end
puts combine(array_one, array_two)
# # Write a program that prints the numbers from
# # 1 to 100. But for multiples of three print "Fizz"
# # instead of the number and for multiples of five print "Buzz".
# # Print "FizzBuzz" for numbers that are multiples of both 3 and 5.
# #
for i in 1..100
if i % 3 == 0 && i % 5 == 0
puts "FizzBuzz"
elsif i % 3 == 0
puts "Fizz"
elsif i % 5 == 0
puts "Buzz"
else
puts "#{i}"
end
end
@marinalaguerre20
Copy link
Author

hello Zack,

I did this homework a couple times to make sure that I could do it without help.
I had a problem with the finding the max exercise. I couldn't do it without using the max function. and the code you gave me it wasnt working .., please let me know what id did wrong.

For the combining array exercise, I added an input to it, it works but i was wondering why the user has to put commas in the input when i already used the .split .

thank you,
Marina

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment