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
[MUSIC] 0:00 Let's practise some basic Ruby to make sure that everything you've learnt so 0:04 far sticks. 0:08 We'll review had to define a method that accepts some parameters and 0:08 returns a value and then how to call that method. 0:11 We're going to ask you to build a simple Ruby program that calculates the area and 0:13 perimeter of a rectangle. 0:18 I've attached a workspace to this video which includes 0:19 a rectangle.rb starter file with instructions as Ruby comments. 0:23 You should open the workspace now. 0:27 If you have Ruby installed on your computer, 0:30 you can choose File > Download Workspace, and then edit and 0:32 run the files locally or you can just set it and run everything in the workspace. 0:36 Write your code in the rectangle.rb file and save your work. 0:41 Then, switch to the terminal and type rubyrectangle.rb to run your program. 0:44 I've linked to some videos in the teachers notes, 0:50 which you can refer to if you get stuck. 0:52 After you've written your program, 0:54 you can proceed to the next video where you can compare my solution to yours. 0:56 Ready? 1:00 Get started on your program. 1:00 I'll show you my version in the next video. 1:02
You need to sign up for Treehouse in order to download course files.Sign up