Skip to content

Instantly share code, notes, and snippets.

@chug2k
Last active December 22, 2015 19:29
Show Gist options
  • Save chug2k/6520262 to your computer and use it in GitHub Desktop.
Save chug2k/6520262 to your computer and use it in GitHub Desktop.
method practice for zaidi
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"
@zaidi11c
Copy link

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