Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialnathanielcusano
9,808 PointsWhy do we call the functions at the bottom of the program rather than in between each function?
def get_name() #gets a variable that is a name
print "Enter your name: "
return gets.chomp
end
name= get_name() #your calling the function but unless you set it equal to name, it won't be able to be stored for furthur use letter in other functions.
def greet(name)
puts "Hi, #{name}!"
if (name== "Nathan")
puts "That's a great name!"
end
end
greet(name)
def get_number()
print "What number would you like to test?"
return gets.chomp.to_i
end
number= get_number()
def divisible_by_3?(number)
return (number%3==0)
end
#functions called in correct order
if divisible_by_3?(number)
puts "Your number is divisible by 3"
else
puts "Your number is not cleanly divisible by 3"
end
nathanielcusano
9,808 Pointsnathanielcusano
9,808 Pointsas opposed to