We will: examine reasons for using custom blocks and enhance code by using custom blocks. I will: write my own custom block.
Lesson Objectives
How comfortable do you feel with creating and using custom blocks in Scratch?
- I can teach it
- I can do it
- I need some help
Custom blocks in Scratch are called functions, methods, sub-programs, or procedures in other programming languages. Custom blocks allow you to store a chunk of code together that serves a certain purpose.
What is a custom block?
You can use a custom block to: Reduce lines of code by storing repeated code in a custom block Organize code in a meaningful way that makes it easier to read
What is a custom block?
We first define a custom block, then we call the custom block as many times as we want in our main code.
Example 1
This custom block has a numerical input (also called parameter) for the height. Height is now used like a variable.
Example 2
1) look over the code 2) discuss with your partner where a function may be useful 3) share with class
Think Pair Share 1
1) look over the code 2) discuss with your partner where a function may be useful 3) share with class
Think Pair Share 2
Create a simple program using a custom block that makes the sprite rotate 360 degrees. Can you extend it by using an input?
You Try!
What is one reason why you might use a custom block in Scratch?
How confident are you with today's lesson?
- Very confident 💪🏻
- Somewhat confident 😊
- Neutral 🤷🏻♂️
- Not very confident 😕
- No confidence at all 🙁