Created
July 11, 2013 19:36
-
-
Save vcabansag/5978533 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Exploring methods | |
def introduce(first_name, last_name) | |
puts "Hello! My name is #{first_name} #{last_name}." | |
end | |
# Ruby creates local variables called first_name and last_name and | |
# assigns the inputs (or arguments) into them | |
# The technique above is called "string interpolation". | |
# When you have a double-quoted string, you can inject | |
# ruby expressions into it by wrapping them with #{} | |
# It's shorthand for this: | |
# puts "My name is " + first_name + " " + last_name + "." | |
introduce "Vince ", "Cabansag" | |
# Using the .methods to find new methods in Ruby | |
students array | |
string | |
integer | |
# Challenge | |
# Based on the data stored in the shopping_cart, sales_tax, and | |
# params variables below, write code that prints out the customer's total, including | |
# estimated sales tax, based on the shipping address they entered. Your code should | |
# work even if the values of the data change. | |
# Your output should look like this: | |
# Your total with tax is $7808.06. | |
# shopping_cart = [ | |
# {'name' => "iPad 2", 'price' => 499, 'quantity' => 2}, | |
# {'name' => "iMac 27", 'price' => 1699, 'quantity' => 3}, | |
# {'name' => "MacBook Air 13", 'price' => 1299, 'quantity' => 1} | |
# ] | |
# sales_tax = {"IL" => 0.115, "IN" => 0.09, "MI" => 0.06, "WI" => 0.056} | |
# params = { | |
# 'name' => "Patrick McProgrammerson", | |
# 'address1' => "222 W Merchandise Mart Plz", | |
# 'address2' => "Suite 1212", | |
# 'city' => "Chicago", | |
# 'state' => "IL", | |
# 'zip' => "60654" | |
# } | |
# Hint: First try doing it yourself by hand, and notice the steps you are taking. | |
# You will have to translate these instructions into Ruby. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment