Scratch Code Examples: Learn Scratch Programming (2024)

Scratch is a simple, fun coding platform designed especially for kids. We teach Scratch in our elementary school coding program, but even adults can enjoy coding with Scratch. The Scratch platform does a pretty good job of making it easy to jump into coding, but even the simplest programs are intimidating for someone who is just getting started. It’s helpful to see Scratch code examples and try them out for yourselves. After all, it’s a brand-new interface with buttons, blocks, and more.

📌 [Download] Printable Scratch Coding Tutorials Get 2 printable Scratch tutorials, Rocket Landing and Flying Space Cat, to code your own games step by step. Download Now

We’re going to take a look at different Scratch code examples and what they do, but first, what is Scratch and why should you care?

Learn Programming in Scratch

Scratch is a free platform for learning how to code. It’s popular in large part because MIT put a ton of work into making Scratch programming language easy to understand and use. It’s a block-based coding language and allows users to drag and drop colorful blocks of code to build animations or games.

While the way learners interact with the code is simplified, the code itself is not. Each block represents a chunk of real code, which means kids are learning real coding concepts when they work in Scratch. As such, Scratch is a great platform for teaching your child coding concepts like conditionals and loops, exploring how (X,Y) coordinates work, or what exactly an “event” is in coding.

If that sounds interesting, you can also check out our Scratch coding classes for kids!

Recommended:Kids Coding Websites

Scratch Code Examples: Learn Scratch Programming (1)

Scratch Code Examples for Beginners

Scratch builds complete programs by connecting a series of code blocks together. Each block represents a piece of real code inside that users can string together to make things happen. In a Scratch program, different kinds of blocks have different colors and names that tell you the type of block it is and what job it does.

Let’s take a look at a few Scratch code examples. These are some of the most common blocks in beginner Scratch programs and what they do.

  • Event blocks
  • Motion blocks
  • Looks Blocks
  • Sound Blocks
  • Control Blocks

You can also see how these example blocks work together to build a complete project, like our Scratch Valentine’s Day tutorial.

Scratch Code Examples: Learn Scratch Programming (2)

Event Blocks

The orange blocks in Scratch, usually with a rounded top, are event blocks.

In most cases, the event blocks are the ones that begin each sequence of code. They usually can’t be added below other blocks on a chain. Their job is to wait for a specific event to happen or send a message to other blocks so they can tell the code blocks below them to go!

Scratch code blocks that aren’t attached to an event block won’t run, so event blocks are a necessary part of every program.

When Green Flag Clicked

The “When Green Flag Clicked” event block starts a chain of code when the green flag button is clicked. This is commonly used as the way to start the code for an animation or game that doesn’t need other interaction from the person playing it. Essentially, it’s a start button to get your code going!

Scratch Code Examples: Learn Scratch Programming (3)

When Key Pressed

The “When Key Pressed” event block starts a section of code when a specific key is pressed on the keyboard. It’s useful for when you want something to happen when the user presses a key, like getting a sprite (a character or image) to move around.

Scratch Code Examples: Learn Scratch Programming (4)

When This Sprite Clicked

In Scratch programming, sprites are elements and characters in your project. The “when this sprite clicked” event block starts the code when the user clicks on the chosen sprite. This is useful for any Scratch game that involves collecting items by clicking on them or for letting users click on buttons using the mouse. On touchscreens, a click event happens when the user taps on the sprite with their finger.

Scratch Code Examples: Learn Scratch Programming (5)

Motion Blocks

The motion blocks are the blue blocks. These are the blocks that control the movement of the different sprites in your program. Any time you want a sprite to change its position on the screen, these are the blocks that you’ll add.

Move

TThe “move” block is the most basic of the motion blocks. When activated, it will move its sprite the indicated number of steps in the direction the sprite is facing. So, if you wanted to move your sprite 10 steps to the right, you would make sure it is facing 90° (the right side of the screen) and activate the move block.

The white circles inside these blocks have numbers that you can change so you can move the sprite the specific distance that you want.

Scratch Code Examples: Learn Scratch Programming (6)

Turn

The “turn” blocks change the direction your sprite is facing by the number of degrees shown in the white circle. In a maze game, your sprite might need to turn 90° to travel the right path. Remember that the direction a sprite is facing affects the direction that the “move” block takes it.

Scratch Code Examples: Learn Scratch Programming (7)

Go to

The “go to” block will instantly move its sprite to the coordinates shown in its circles.

Scratch Code Examples: Learn Scratch Programming (8)

Glide

The “glide” block will also take its sprite to the set coordinates, but will do it over a number of seconds instead of doing it instantly. This is useful if you want to show the movement instead of just moving the sprite instantaneously.

Scratch Code Examples: Learn Scratch Programming (9)

Looks Blocks

Looks blocks affect how sprites and backgrounds appear to the user. This is great for making sprites look like they are Looks blocks affect how sprites and backgrounds appear to the user. This is great for making sprites look like they are moving or for changing the scenery in animations. Changing the looks of a block is a separate task from changing its position. If you want to make a sprite appear to be walking, you’ll need to activate both a motion block and a looks block.

Switch Costume

Changing the looks of a sprite is done by switching between costumes. Costumes are different pictures that are all connected to a single sprite. When the “switch costume” block is activated, its sprite will change to the specific costume shown in the dropdown menu.

Scratch Code Examples: Learn Scratch Programming (10)

Switch Backdrop

Changing the looks of the scenery is done by switching between backdrops. When the “switch backdrop” block is activated, the picture used as the background will change to the backdrop indicated in the dropdown.

Scratch Code Examples: Learn Scratch Programming (11)

Show and Hide

The show and hide blocks affect the visibility of sprites. If there is a sprite that you don’t want visible on the screen, the “hide” block can make it invisible, but still a part of your program. Likewise, if there is an invisible sprite on the screen that you want to make visible, the “show” block will make it visible.

Scratch Code Examples: Learn Scratch Programming (12)

Sound Blocks

Sound blocks are blocks that affect the audio playing instead of anything visual. You can choose specific sound files included on Scratch, upload your own files, or even record directly in the program if you like.

Of the three most commonly used sound blocks, two will play your chosen sound file, but there’s a major difference between them.

Play Sound Until Done

The “play sound until done” block will play the file until it finishes before activating the next block. This keeps sounds from overlapping each other, which could make any dialogue difficult to understand. It’s also useful if you want a sprite to finish saying what he’s saying before moving.

Scratch Code Examples: Learn Scratch Programming (13)

Start Sound

In contrast, the “start sound” block will play a sound, but will also instantly activate the next block in line. This is useful if you want to stack sounds on top of each other, or activate another block while the sound is playing.

Scratch Code Examples: Learn Scratch Programming (14)

Stop All Sounds

The “stop all sounds” button does just what it says. When this block is activated, it will stop all sounds from playing. Note that this doesn’t pause or mute them, it stops them from playing. That means that sound files will start over from the beginning if they are activated again.

Scratch Code Examples: Learn Scratch Programming (15)

Control Blocks

Control blocks don’t directly affect sprites, backdrops, or audio. Instead, they control when and how often other blocks get activated. That gives you the ability to code loops, add in delays, and generally increase the amount of control you have over your code.

Wait

The “wait” block keeps code blocks from activating directly after the block ahead of them. This is useful for making sure block actions happen exactly when you intend them to.

Scratch Code Examples: Learn Scratch Programming (16)

Repeat

“Repeat” blocks are used to create code loops. When a “repeat” block is activated, it will repeat whatever other blocks it contains for the specified number of times before activating any block underneath. This helps a ton in keeping the overall length of code down and helps in avoiding small mistakes in repeating code.

Scratch Code Examples: Learn Scratch Programming (17)

Forever

The “forever” block is a special loop block that will continue activating whatever blocks it contains until it is made to stop. This is especially useful for things like creating background music or other actions that you don’t want to stop.

Scratch Code Examples: Learn Scratch Programming (18)

💻 Scratch classes for kids ages 8-10. Learn Scratch with fun and enagaging, live coding classes. View Elementary School Program.

Scratch Game & App Tutorials

Learn how to create a simple game or application with these free projects. Find full Scratch code examples in our programming tutorials.

Learn Coding5 Popular Game Mechanics in Scratch [60 Second Lessons]January 12, 2024
Learn CodingHow to Make Flappy Bird on ScratchApril 28, 2023
Learn CodingScratch Tutorial For Kids: Flying Space CatDecember 5, 2022
Learn CodingSimple Scratch Tutorial for Kids: Code a Rocket Landing GameUpdated on September 14, 2023

Download Free Printable Scratch Coding Tutorials PDF

Get the Rocketship Landing game and Flying Space Cat Scratch tutorials in a printable format.

Make Games & Apps in Scratch

Now that you have the hang of the basic kinds of Scratch blocks, it’s time to put them to use!

Everything you can make in Scratch is created through combinations of the different kinds of blocks, and there is no better way to learn than by jumping in and trying it out yourself. But if you’re interested in getting a head start on learning, be sure to check out CodeWizardsHQ’s Scratch coding classes.

Good luck, and happy Scratching!

Scratch Code Examples: Learn Scratch Programming (2024)

FAQs

What are Scratch programming examples? ›

What is Scratch coding? Scratch is a free block-based coding platform that allows you to create your own games, stories, and animations. On Scratch, you can program many different types of projects, such as a Magic Pen, Wizard Tag Game, Geometry Dash, Basketball Game, Pacman, or Snake.

How can I learn Scratch programming? ›

Learn Scratch scripts

Programming in Scratch is done through the scripts that you will find in the "Code" tab. These scripts are executed when you connect them to the blocks you have already designed in the project. It's as easy as choosing the script and dragging it to the block where you want it to run.

Is Scratch a good start to learn programming? ›

Scratch coding is the best programming language for child and teen beginners, especially for younger students. However even for middle and high schoolers can benefit from learning with it too.

Is Scratch safe for 10 year olds? ›

Scratch is designed especially for young people ages 8 to 16, but people of all ages create and share with Scratch. Younger children may want to try ScratchJr, a simplified version of Scratch designed for ages 5 to 7.

Is Scratch a Python code? ›

Purpose: Scratch is a visual programming language that is specifically designed for kids and beginners to learn to code, while Python is a general-purpose programming language that is used for a wide range of applications, including web development, data analysis, and scientific computing.

Is Scratch coding real coding? ›

Scratch is the world's largest coding community for children and a coding language with a simple visual interface that allows young people to create digital stories, games, and animations. Scratch is designed, developed, and moderated by the Scratch Foundation, a nonprofit organization.

How fast can you learn Scratch? ›

For some, it may take as little as a month to three months and for some, it may take up to six months or more. Some kids naturally learn faster than others, while some kids use better resources, which accelerates their learning process.

How hard is Scratch coding? ›

It uses a drag and drop method which lets children perform actions quickly and easily. This approach is what makes Scratch not hard to learn, and easy to get started with. Things like omitting a comma and forgetting to close a bracket are eliminated, creating more focus on programming concepts.

How long does it take to learn coding from Scratch? ›

It may take six months to a year to become a skilled coder in your chosen languages. The hardest part is to get started and keep going, even when you face obstacles. Coding consistently on different projects will help you build problem-solving skills.

Should kids learn Scratch or Python? ›

Scratch is best suited for younger kids who want to learn basic coding concepts and create fun projects, while Python is better suited for older kids who want to learn a versatile language with many real-world applications.

What are the disadvantages of using Scratch? ›

What are Scratch's limitations? There are some limitations to Scratch, like that it does not offer a progression to text-based programming languages; it is missing features for advanced coders, and it does not offer an option for making 3D projects.

What is the best age to learn Scratch? ›

According to the official Scratch website, the Scratch programming language is appropriate for children aged 8 to 16, but children as young as 5 and people of all ages use it.

Is Scratch coding free? ›

Scratch, developed by the Massachusetts Institute of Technology (MiT), is a free online platform for learning visual coding. On Scratch, you can create animations and games which can be uploaded to the site for others to use and share.

How to start teaching Scratch? ›

Set up a Scratch Teacher Account. The Scratch Teacher Account guide includes support for account set up, class creation, password tips, and making teacher studios where students can share their Scratch projects with you and their peers.

What is the average age of Scratch users? ›

Created 15 years ago as part of a MIT project to introduce less clunky software for kids to learn coding, Scratch has over 42 million active users across 200 countries, with an average age of 12.

What is Scratch code used for? ›

Scratch coding is the process of writing and running programs using Scratch, a free programming language and code editor that helps young learners understand coding logic using blocks and visual aids. Scratch is a programming platform for children which was created by the MIT Media Lab in 2007.

What can I do with Scratch coding? ›

With the Scratch Coding Cards, you can learn to create interactive games, stories, music, animations, and more!

What are the 3s of Scratch programming? ›

It's important to know that the Scratch interface is divided into three sections: the stage area, block palette and coding area.

What is the difference between Scratch and coding? ›

Scratch is designed to be easy to use, with a drag-and-drop interface that allows kids to create programs without having to type out code. This can be a great way for younger kids to learn the basics of coding. Python, on the other hand, is a text-based language that requires kids to learn how to type out code.

References

Top Articles
2025 BMW M8 Review, Pricing and Specs
What is the top speed of BMW 8 Series? | 8 Series FAQ
Northern Counties Soccer Association Nj
Lengua With A Tilde Crossword
Kreme Delite Menu
Compare Foods Wilson Nc
Monthly Forecast Accuweather
Fort Carson Cif Phone Number
Publix 147 Coral Way
World Cup Soccer Wiki
Helloid Worthington Login
Jasmine Put A Ring On It Age
Winterset Rants And Raves
Gas Station Drive Thru Car Wash Near Me
Sams Early Hours
Simon Montefiore artikelen kopen? Alle artikelen online
Calmspirits Clapper
Interactive Maps: States where guns are sold online most
Dutch Bros San Angelo Tx
Imagetrend Inc, 20855 Kensington Blvd, Lakeville, MN 55044, US - MapQuest
Effingham Bookings Florence Sc
Ups Print Store Near Me
Craigslistodessa
Best Sports Bars In Schaumburg Il
Target Minute Clinic Hours
Обзор Joxi: Что это такое? Отзывы, аналоги, сайт и инструкции | APS
Rek Funerals
Watson 853 White Oval
The Powers Below Drop Rate
Rubmaps H
Gasbuddy Lenoir Nc
Memberweb Bw
LEGO Star Wars: Rebuild the Galaxy Review - Latest Animated Special Brings Loads of Fun With An Emotional Twist
Ixl Lausd Northwest
No Hard Feelings Showtimes Near Tilton Square Theatre
Consume Oakbrook Terrace Menu
Metra Schedule Ravinia To Chicago
Chuze Fitness La Verne Reviews
How to Draw a Sailboat: 7 Steps (with Pictures) - wikiHow
Überblick zum Barotrauma - Überblick zum Barotrauma - MSD Manual Profi-Ausgabe
Academy Sports New Bern Nc Coupons
Immobiliare di Felice| Appartamento | Appartamento in vendita Porto San
Umd Men's Basketball Duluth
Lamont Mortuary Globe Az
Panolian Batesville Ms Obituaries 2022
Reilly Auto Parts Store Hours
Ssc South Carolina
Market Place Tulsa Ok
The top 10 takeaways from the Harris-Trump presidential debate
53 Atms Near Me
Superecchll
Charlotte North Carolina Craigslist Pets
Latest Posts
Article information

Author: Kerri Lueilwitz

Last Updated:

Views: 5916

Rating: 4.7 / 5 (47 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Kerri Lueilwitz

Birthday: 1992-10-31

Address: Suite 878 3699 Chantelle Roads, Colebury, NC 68599

Phone: +6111989609516

Job: Chief Farming Manager

Hobby: Mycology, Stone skipping, Dowsing, Whittling, Taxidermy, Sand art, Roller skating

Introduction: My name is Kerri Lueilwitz, I am a courageous, gentle, quaint, thankful, outstanding, brave, vast person who loves writing and wants to share my knowledge and understanding with you.