Last active
December 22, 2015 19:29
-
-
Save chug2k/6520262 to your computer and use it in GitHub Desktop.
method practice for zaidi
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
def greet(name) | |
"Hello #{name}!" | |
end | |
# Copy and paste that into irb. | |
# then type: | |
# greet("Zaidi") | |
# Pretty clear, right? | |
# Now, let's do something a little more interesting. | |
def greet_with_time_of_day(name, time_of_day) | |
"Good #{time_of_day}, #{name}!" | |
end | |
# Now type: | |
# greet_with_time_of_day("Zaidi") | |
# You should get an argument error. Why? | |
# --> Enter in why: | |
# | |
# | |
# Okay. So how do we fix it? | |
# greet_with_time_of_day("Zaidi", "Morning") | |
# Okay. Now let's try this: | |
def greet_with_time_of_day_excited(name, time_of_day, excited) | |
greeting = "Good #{time_of_day}, #{name}" | |
if excited | |
greeting << "!!!!!!!!!!!!" | |
end | |
greeting | |
end | |
# Please tell me how I would call the greet_with_time_of_day_excited function | |
# in order to get the following output: | |
# "Good afternoon, Charles!!!!!!!!!!!!" | |
# And please tell me how I would get the following output: | |
# "Good evening, Bill" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://db.tt/qt8MzpnT