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 is the Scratch question answer? ›

Scratch is a visual programming language that allows students to create their own interactive stories, games and animations. As students design Scratch projects, they learn to think creatively, reason systematically, and work collaboratively.

How hard is Scratch coding? ›

Is Scratch easy to learn? Beginners should not find Scratch hard to learn since it is use visual elements and simplified drag and drop functionality. It has been created specifically for kids with the primary purpose of giving them an early exposure to understanding the basics of coding and programming.

How do I learn to code from Scratch? ›

How to Start Coding
  1. Figure out why you want to learn to code.
  2. Choose which coding language you want to learn first.
  3. Take online courses.
  4. Watch video tutorials.
  5. Read books and ebooks.
  6. Use tools that make learning to code easier.
  7. Check out how other people code.
  8. Complete coding projects.
Jul 9, 2024

Is Scratch good or bad? ›

scratch is a good coding website, but get this, the moderation is absolutely horrible. for example, many people get mass-reported and banned for no reason, likewise my account, Iamdudeboy, which got banned for self injury when i had just gotten off it.

What is say hello in Scratch? ›

To change what is displayed in the speech bubble on the Stage, you can click on the white input bubble that says “Hello” in the Code Area and type what you want your sprite to say.

Why is Scratch so easy? ›

The Scratch Coding programming environment is based on a block-based interface that makes it easy to understand and use.

Can a 5 year old learn Scratch? ›

What is the age range for Scratch? 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.

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.

Is Scratch harder than Python? ›

Both Scratch and Python are beginner-friendly and easy-to-learn coding languages for kids. Plenty of resources are available to learn Python and Scratch, but Scratch would be the best option if your child is new in the programming field.

Is Scratch real coding? ›

Scratch is a free helpful tool, developed by the MIT Media Lab, for learning how to code. It is a visual block-based programming language that is designed to be easy to use and understand, especially for beginners.

How long will it take me to learn coding from Scratch? ›

Generally, most people can learn basic coding skills in as little as three to four months. Developing more profound programming knowledge takes most people between six months and a year. The process of learning to program requires you to learn new concepts and languages, such as HTML, Java, or Python.

Can you self learn code? ›

Yes, it is possible to learn to code by yourself. There are millions of resources available both online and physically.

How can I memorize codes easily? ›

How to Memorize Codes: Tips & Tricks
  1. 1.1 1. Remember to Implement.
  2. 1.2 2. Don't Just Watch or Read.
  3. 1.3 3. Use Online Coding Tools.
  4. 1.4 4. Developer Tools.
  5. 1.5 5. Share Your Knowledge.
  6. 1.6 6. Be Patient & Confident.
Dec 21, 2022

What is the question answer game? ›

Question games are activities that use prompts to reveal personal answers about players. For example, “Never Have I Ever”, Icebreaker Questions and Truth or Dare? The purpose of these games is to build relationships, boost engagement and have fun.

What is the Scratch test for? ›

Scratch testing is a simple and rapid method of characterizing coatings, but results obtained are influenced by various factors such as coating thickness, substrate mechanical properties, interfacial bond strength, and test conditions such as scratch speed, load, and indenter tip radius.

What is the saying about Scratch? ›

Happiness is having a scratch for every itch. Scratch a dog and you'll find a permanent job. Few people even scratch the surface, much less exhaust the contemplation of their own experience. Fatherhood is great because you can ruin someone from scratch.

Top Articles
Step-by-Step Recipe on How to Make Caramelized Pecans
Pumpkin Pie Cupcakes Recipe
Sugar And Spice 1976 Pdf
William G. Nolan - Baker Swan Funeral Home
Renfield Showtimes Near Amc Kent Station 14
211475039
Celebrity Guest Tape Free
Heat Pump Repair Horseshoe Bay Tx
Myvetstoreonline.pharmacy
Metro By T Mobile Sign In
Mayo Webscheduler
William Spencer Funeral Home Portland Indiana
Wmlink/Sspr
Nyu Paralegal Program
Walgreens Dupont Tonkel
Sophia Turner Derek Deso Instagram
Walking through the Fire: Why nothing stops Jesus’ love for you - Ann Voskamp
Dmv Rocklin Wait Times
Glenwood Apartments Logan Utah
Warren P. on SoundBetter
Post Crescent Obituary
Emma D'arcy Deepfake
What Happened To Zion Judah Satterfield
Thermal Pants Mens Walmart
Education (ED) | Pace University New York
Jennifer Beals Bikini
MySDMC SSO: Manatee County’s Digital Educational Access
Journal articles: 'Mark P. Herschede Trust' – Grafiati
Craigslist Pikeville Tn
Morgan Plus Four 2024 review
Eureka Mt Craigslist
Best 43-inch TVs in 2024: Tested and rated
Metro By T Mobile Sign In
Rolling-Embers Reviews
1084 Sadie Ridge Road, Clermont, FL 34715 - MLS# O6240905 - Coldwell Banker
100X35 Puerto Rico Meaning
Hispanic supermarket chain Sedano's now delivering groceries in Orlando
Jbz Inlog
Osrs Desert Heat
Teamnet O'reilly Login
Where does the Flying Pig come from? - EDC :: Engineering Design Center
Seattle Rpz
Bronx Apartments For Rent Craigslist
Optum Director Salary
Degreeworks Sbu
Amazing Lash Bay Colony
Cibo Tx International Kitchen Schertz Menu
Steel Punchings For Sale
Larry's Country Diner LIVE! - 2024 Tickets - Branson Travel Office
A Man Called Otto Showtimes Near Cinemark Palace 20
Democrat And Chronicle Obituaries For This Week
Mcknet Workday
Latest Posts
Article information

Author: Errol Quitzon

Last Updated:

Views: 5541

Rating: 4.9 / 5 (59 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Errol Quitzon

Birthday: 1993-04-02

Address: 70604 Haley Lane, Port Weldonside, TN 99233-0942

Phone: +9665282866296

Job: Product Retail Agent

Hobby: Computer programming, Horseback riding, Hooping, Dance, Ice skating, Backpacking, Rafting

Introduction: My name is Errol Quitzon, I am a fair, cute, fancy, clean, attractive, sparkling, kind person who loves writing and wants to share my knowledge and understanding with you.