## ← Creating Functions in Code Studio by Bill Gates and Saloni

• 1 Follower
• 19 Lines

### Get Embed Code x Embed video Use the following code to embed this video. See our usage guide for more details on embedding. Paste this in your document somewhere (closest to the closing body tag is preferable): ```<script type="text/javascript" src='https://amara.org/embedder-iframe'></script> ``` Paste this inside your HTML body, where you want to include the widget: ```<div class="amara-embed" data-url="http://www.youtube.com/watch?v=EoUnJB_BVLc" data-team="null"></div> ``` 3 Languages

Showing Revision 1 created 02/27/2017 by 奕德 余.

1. One of the great things in computer programming
is once you've taught a computer how to do
2. an action, you can call that function again.
You give it a name and then you can call it.
3. That's really like extending the language.
In the program we built, we learned how to
4. draw a square by moving and turning four times.
We can take that function and give it a name,
5. draw a square so that any time we want to
do that, we simply say draw a square and it
6. will go back and invoke that function, that
code and it will get done for us. We've added
7. that concept to our programming language.
In this puzzle, we have already created a
8. draw a square function for you. You'll see
it in the toolbox as a green block. What you'll
9. need to do is write the same code you wrote
before to draw a square and put it in this
10. function. To do that, click on the edit option
in the green draw a square block. This will
11. open up the function editor. The function
editor has three parts. A place where you
12. name your function. This will appear on the
green block before that function. Then write
13. out a short description of what your function
is supposed to do. In this case, it's supposed
14. to draw a square. The white space below this
is the work space and works just like the
15. work space you've already been using. Drag
and drop blocks from the toolbox into this
16. work space. Remember to put the blocks that
create a square inside the green wrapping
17. block for the function. Once you're done,
click on save and exit. This will take you
18. back to the main puzzle work space. Now you
can use the draw the square function block
19. just like any other block to solve the puzzle.