kareemgrant
3/26/2015 - 6:13 PM

basic-ruby-functions.md

Goals

  1. Solidify your understanding of basic Ruby programming concepts

  2. Be prepared for slightly more advanced material on Thursday

Assignment

  1. Create the following functions:
  • Create a function that takes a string and adds the phrase "Only in America!" to the end of it
  • Create a function to find the maximum value in an array of numbers. For instance: [100,10,-1000]

should return 100. Do not use Ruby's built-in .max function.

  • Create a function that takes two arguments - both of them arrays. Inside of the function, combine the arrays using the items from the first array as keys and the second array as values. For example, when these two arrays are supplied as arguments:
  [:toyota, :tesla]
  ["Prius", "Model S"]

they should return a hash like so:

  {toyota: "Prius", tesla: "Model S"}
  1. 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.

Hint: look up modulo

Recommended Activity Complete as much of the "Introduction to Ruby" track on Codecademy as you can. http://www.codecademy.com/courses/ruby-beginner-en-d1Ylq?curriculum_id=5059f8619189a5000201fbcb

Try the "Ruby in 20 minutes" primer: http://www.ruby-lang.org/en/documentation/quickstart/