21. Smarter, not harder

One of the most awesome aspects of programming is creating code that is elegant and saves you time. In our lessons so far we have created a few nifty procedures, and used a few variables. In this lesson we are going to make a procedure that is adjustable... because of those variables.
Lets clear the screen and begin.
The hard way. Lets start by doing things to old fashioned way. Make a rectangle on your screen
Make a 50 by 70 rectangle using the fd and right commands on your screen
Repeat after me... Can you think of anything else we could have done to shorten the code we just used? Was anything repetitive?
Lets try the command again
What about those variables I mentioned? Do the words Width and Length come to mind? When we learned about variables earlier we used the make command. Lets do the same here
Make a variable :W = 50 and a :L = 70
Now lets put that in our old repeat formula
The only catch is we change the original numbers to variables
This is where the true power comes into play. We need to make it a procedure. I am going to choose the name rec because it is short and sweet. We want it to draw a custom rectangle each time, so we need to "ask"
Create the new rec procedure
This is the fun part. You now have the ability to make any rectangle by simply calling the procedure rec and typing 2 numbers after it.
See if you can draw a 60 by 10 rectangle
TurtleAcademy learn programming for freeYour browser is not supporting canvasWe recomand you to use Chrome or Firefox browsers