Ready to learn how to make Tic Tac Toe on Scratch? With Scratch coding, you can bring this traditionally paper-and-pencil game for two players into the digital realm. In this game, each player makes one type of mark, either: X or O, and each player takes turns marking the spaces in a 3×3 grid with their mark. The winner is the player who gets three in a row!

So today, we'll guide you through simple steps to bring this game to life, and provide you with a few fun examples of ways to get creative with your version of the game. Let's get started!

By the way, we also have a special fun Scratch Pokemon game class right now. Join our live online award-winning Game Building class for expert guidance and fun Scratch projects every week:

How to make Tic Tac Toe on Scratch

In this tutorial, we will show you how to make a simple Tic Tac Toe game on Scratch using variables and lists. Follow along as we break down the logic to help you create your own Tic Tac Toe game. Here's what our completed project will look like.

1. One button, three costumes

There are three rows and three columns which makes for a total of 9 possible slots where X and O are placed. Let’s start with one Sprite: Button. Make two more costume: One for X and one for O. The third one will be used to represent an empty slot:

Make tic tac toe

2. Our platform

Simply right-click Button Sprite and select duplicate to make 8 more, then arrange them side by side into three rows and three columns:

Platform columns

3. Start the game

Now is a good time to think of the first thing we should see once the game starts. We first want to see the third costume for the button (the one without the X/O). We also want to lock in a position for each button just in case they get shuffled around during the game:

Code to start the game

4. Whose turn?

Next, let’s create a variable to keep track of our turns. Since the game always starts with an X, we’ll use the mod block to display costume with an X if the number of clicks is odd, otherwise the costume with the O will show:

Create a variable for coding

5. List variables for X’s and O’s

Now that we can keep track of turns or XO’s, we need to create a list variable to store that information so that we can determine the winner. In Variables, click on Make a List for an X list and do the same for an O list. Then, use the “add ‘thing’ to” block to add to our lists. Do this for the rest of the Buttons but be sure to change the text for our list variables (x-button2; x-button3, o-button2, o-button3):

List variables for Xs and Ox

6. Determine what’s inside and who won

And finally, it is time to check what’s inside of our list variables to announce a winner. There are a total of 8 possible ways to win (each row, each column, and diagonally for each side). If a list has one of the three descriptions that fall under a winning list, then we need to announce the winner. For example, if X list has x-button1, x-button2, and x-button3, which represent the first row of the game, then we have a winner. Use if/then condition to check all 8 possible solutions for both the X and the O list:

Determine what's inside and who won

Examples of Tic Tac Toe on Scratch

Now that you've created an awesome Tic Tac Toe game, here are a few variations to inspire your creativity.

1. A semi-challenging Tic-Tac-Toe by cairparavel

Want to play against a computer and have the chance to win? Check out this Tic Tac Toe game by cairparavel where the computer always goes first.

2. Stepping it up with Gato y Raton by carlosthan

Perhaps you like the opportunity to win against a computer, but you prefer to go first? Check out Gato y Raton by carlosthan – a Tic Tac Toe game that always waits for its opponents to go first. Just and don’t underestimate the brains behind the curtesy.

3. Unbeatable Tic-Tac-Toe by crazy_ted

Funny username but a very serious game. This Tic Tac Toe game truly lives up to its name: it is unbeatable!! It also uses cloud version and keeps a global score of wins, loses, and ties.

Now you know how to make Tic Tac Toe on Scratch

In this tutorial you’ve learned how to make a simple Tic Tac Toe game on Scratch using variables and lists. We’ve also covered how to switch back and forth between X and O based on turns, and we’ve implemented a way to determine a winner based on the 8 possible solutions for both X and O players.

Learn how to build games like this by taking our advanced Scratch course, designed by professionals from Google, Stanford, and MIT! You can also get started with any of our free coding classes for kids.

Ready for more fun? Up next, find out how to make a Pacman game on Scratch.

Written by Sandra Dizdarevic, a Create & Learn instructor with 6 years of experience teaching STEM to children in the 3rd through 11th grade. She has an Undergraduate as well as a Masters Degree in Management Information Systems from UNO.