Return to Video

Creating Functions in Code Studio by Bill Gates and Saloni

  • 0:04 - 0:11
    One of the great things in computer programming
    is once you've taught a computer how to do
  • 0:11 - 0:22
    an action, you can call that function again.
    You give it a name and then you can call it.
  • 0:22 - 0:29
    That's really like extending the language.
    In the program we built, we learned how to
  • 0:29 - 0:39
    draw a square by moving and turning four times.
    We can take that function and give it a name,
  • 0:39 - 0:46
    draw a square so that any time we want to
    do that, we simply say draw a square and it
  • 0:46 - 0:54
    will go back and invoke that function, that
    code and it will get done for us. We've added
  • 0:54 - 1:01
    that concept to our programming language.
    In this puzzle, we have already created a
  • 1:01 - 1:06
    draw a square function for you. You'll see
    it in the toolbox as a green block. What you'll
  • 1:06 - 1:10
    need to do is write the same code you wrote
    before to draw a square and put it in this
  • 1:10 - 1:17
    function. To do that, click on the edit option
    in the green draw a square block. This will
  • 1:17 - 1:21
    open up the function editor. The function
    editor has three parts. A place where you
  • 1:21 - 1:27
    name your function. This will appear on the
    green block before that function. Then write
  • 1:27 - 1:32
    out a short description of what your function
    is supposed to do. In this case, it's supposed
  • 1:32 - 1:37
    to draw a square. The white space below this
    is the work space and works just like the
  • 1:37 - 1:42
    work space you've already been using. Drag
    and drop blocks from the toolbox into this
  • 1:42 - 1:47
    work space. Remember to put the blocks that
    create a square inside the green wrapping
  • 1:47 - 1:52
    block for the function. Once you're done,
    click on save and exit. This will take you
  • 1:52 - 1:57
    back to the main puzzle work space. Now you
    can use the draw the square function block
  • 1:57 - 1:59
    just like any other block to solve the puzzle.
Title:
Creating Functions in Code Studio by Bill Gates and Saloni
Video Language:
English
Duration:
02:01

English subtitles

Revisions