Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Introducing the Practice1:04 with Jay McGavren
Let's practice some basic Ruby to make sure that everything you've learned so far sticks. We'll review how to define a method that accepts some parameters and returns a value, and then how to call that method.
Ruby math operators
Add two numbers:
2 + 1
Subtract two numbers:
2 - 1
Multiply two numbers:
2 * 2
You can also do math operations on numeric values stored in variables:
length = 2 width = 4 puts length * width
You can ensure one operation takes place before any others by surrounding it with parentheses:
# Add length and width, THEN double the result (length + width) * 2
Let's practise some basic Ruby to make sure that everything you've learnt so
We'll review had to define a method that accepts some parameters and
returns a value and then how to call that method.
We're going to ask you to build a simple Ruby program that calculates the area and
perimeter of a rectangle.
I've attached a workspace to this video which includes
a rectangle.rb starter file with instructions as Ruby comments.
You should open the workspace now.
If you have Ruby installed on your computer,
you can choose File > Download Workspace, and then edit and
run the files locally or you can just set it and run everything in the workspace.
Write your code in the rectangle.rb file and save your work.
Then, switch to the terminal and type rubyrectangle.rb to run your program.
I've linked to some videos in the teachers notes,
which you can refer to if you get stuck.
After you've written your program,
you can proceed to the next video where you can compare my solution to yours.
Get started on your program.
I'll show you my version in the next video.
You need to sign up for Treehouse in order to download course files.Sign up