Happy holidays! Tis’ the season to be merry and bright and also the perfect weather for a cup of hot chocolate.
Who doesn’t love all of the twinkling lights and decorations this time of year and, of course, the presents under the tree (especially the surprises!).
It’s been a little harder to shop for gifts this year, but that gives us the chance to get creative. If you want to learn how to code, there happens to be plenty you can gift without leaving the house. For you, we’ve created a codable Scratch gift that you can personalize and share with someone you care about.
Code your own Holiday Advent Calendar in Scratch and slowly reveal gifts, goodies, or games to your family and friends.
Our advent calendar counts down until Christmas, but you can make yours for any holiday or special event. It’s a fun way to keep in touch and give a gift that comes from the heart.
Put on your matching pajamas, and let’s get coding!
See Complete Holiday Advent Calendar
What you need:
- Scratch account: Create a free Scratch account
- Starter template: Use this Scratch starter template as the basis of your project. View starter template
No coding experience necessary for this tutorial. Beginner-friendly for ages 8 and up. Give it a try!
Table of Contents
- Step 1: Remix the starter project
- Step 2: Add a gift for December 15
- Step 3: Show the December 15 gift on click
- Step 4: Hide the gift after you view it
- Step 5: Add logic to lock the future gifts
- Step 6: Show an error when you try to open future gifts
- Step 7: Hide the error message after 1 second
- Step 8: Add another gift on 16 December
- Step 9: Show the December 15 gift on click
- Step 10: Repeat until complete
- Your advent calendar is complete!
Step 1: Remix the starter project
We’ve set up the base files for you. Instead of creating a new project, start by remixing a project.
- Sign in to https://scratch.mit.edu
- Go to the starter scratch project https://scratch.mit.edu/projects/461157556/
- Click “Remix” to create a new version you can edit
Hint: You can personalize your calendar with your own background and sprite images.
Step 2: Add a gift for December 15
Our advent calendar starts on December 15. Let’s first add code to the date that tells our gift sprite what gift to open.
- Select the sprite called “dec-15”.
- From the Events category, drag the “when this sprite clicked” block and place it in the playground area.
- Again from the Events category, drag the “broadcast message” block.
- Click on the drop-down arrow, select New Message, and write open-gift-15.
Hint: Instead of a card, you could show an image, animations, or even start a game when you click on the date.
Step 3: Show the December 15 gift on click
When we click our calendar date, we want to reveal the gift. You’ll see some code added to the gift that hides it when we start our game. Let’s show the gift when we click.
- Select the gifts sprite, from the Event category, drag the “when i receive” block, and place it in the playground area.
- Change the value in “when i receive” to open-gift-15.
- From the Looks category, drag the “switch costume” block and place it below “when i receive” block.
- Change value in “switch costume” block to gift-15.
- From the same category, drag the “show” block and place it below the “switch costume” block.
- From the Looks category, drag the “go to layer” block and place it below the “when i receive” block.
- Make sure the value in the “go to layer” block is front.
Step 4: Hide the gift after you view it
The gift shows now! To close it, click on the sprite. The gift covers the whole page so anywhere you click will hide the gift.
- In the gifts sprite, drag the “when this sprite clicked” block to the playground area.
- From the Looks category, drag the “hide” block and place it below when this sprite clicked.
Hint: You could also show the gift for a specific amount of time by using the wait block.
Step 5: Add logic to lock the future gifts
Currently, we are revealing the gift when we click our calendar. Let’s add an if-else statement to help our code decide if it’s time to reveal the gift yet. If it is too early, we’ll show a message instead of our gift.
- Select the dec-15 sprite. Move the broadcast sprite away from the “when sprite clicked” block and place it anywhere in the playground area.
- From the Controls category, drag the “if-else” block and place it below the “when sprite clicked” block.
- From the Events category, drag the “broadcast message” block and place it inside the if code block.
- Change the message in the “broadcast block” to a new message “not yet!”
- Drag the previous broadcast open-gift-15 block from the playground area and place it inside the else code block.
Reveal the gift only if the current date is after the reveal date:
- From the Operators category, drag the > block and place it as a condition in the “if-else” block.
- From the Sensing category, drag the “current year” block and place it on the right side of the > block.
- Change the value in “current year” block to date.
- On the left side of the > block, enter the sprite date i.e., 15.
Hint: For each calendar date sprite, you would change the value in the > block.
Step 6: Show an error when you try to open future gifts
- Select the error sprite from the list of sprites.
- From the Events category, drag the “when I receive” block and place it in the playground area.
- Change the value in “when I receive” block to not yet!
- From the Looks category, drag the “show” block and place it below the “when I receive” block.
Hint: Our error message is an image sprite, you can also upload or draw your own message.
Step 7: Hide the error message after 1 second
- Make sure the error sprite is selected.
- From the Controls category, drag the wait 1 second block and place it below the show block.
- From the Looks category, drag the hide block and place it below the wait block.
Hint: Add a sound to your error message, using play sound block, as a warning!
Step 8: Add another gift on December 16
- Copy the blocks from the dec-15 sprite to dec-16 sprite by dragging them on top of the dec-16 sprite.
- Select the dec-15 sprite, and you will see the copied blocks in it.
- In the “broadcast open-gift-15” block, change the message to open-gift-16.
- Change the value on the left side of > block to 16.
Step 9: Show the December 16 gift on click
- Open the gifts sprite, right-click on the When I receive block, and click on duplicate.
- We get a copy of the blocks, place it anywhere in the playground area.
- Change the message in When I receive block to open-gift-16.
- Set the value of Change costume block to gift-16.
Step 10: Repeat until complete
For each date in your advent calendar, repeat steps 2 through 9.
Your advent calendar is complete!
See Complete Christmas Advent Calendar
You can “see inside” my completed project to get the full Scratch code for this activity.
Take the time to personalize a calendar for your friends and family and give them a gift created by you.
We want to see your Christmas advent calendar too! Share your project in our Facebook group or use #NowYouCode to show us your calendar and prizes.
Download Free Printable Scratch Coding Tutorials PDF
Get the Rocketship Landing game and Flying Space Cat Scratch tutorials in a printable format.
If you want to build more games in Scratch, check out our Elementary School Coding Program. It’s the most fun and effective way to learn Scratch coding and progress to real-world languages like JavaScript and Python.
We wish you all Happy Holidays and a Happy New Year.