Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Practice Ruby Methods!
You have completed Practice Ruby Methods!
Preview
Your goal was to build a simple Ruby program that calculates the area and perimeter of a rectangle. Here's our solution.
Extra credit
- Write a method that accepts the length, width, and height of a box, and returns its volume (
length * width * height). - Write a method that accepts the radius of a circle, and returns its area (
Math::PI * radius ** 2).
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
It's okay if yours is slightly different.
0:00
But if you see something
interesting in my code,
0:00
you should consider borrowing it
to improve your own own program.
0:02
So up here I have defined an area method.
0:06
And it takes two parameters,
a length and a width.
0:08
And that's all that we need to
calculate an area for a rectangle.
0:13
We just multiply the length by the width,
store that in a variable, and
0:17
then return that variable.
0:22
Next step, we were supposed
to define a perimeter method.
0:26
Which, if you visualize a rectangle,
there are two sides where the length is
0:29
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up