Intermediate
+500 XP

👋 Start learning JavaScript right now — for free!

🚀

Assessment: Tic-Tac-Toe Game

Write a complete game in 1–2 hours using everything you've learned

🎓

This is your final assessment!

Imagine you've learned to cook individual dishes: chop vegetables, make broth, fry meat. The final assessment is cooking a complete dinner. Here you'll combine variables, arrays, functions, loops and conditions in one live project.

What we're building

The game Tic-Tac-Toe for two players. A 3×3 board, the first player is X, the second is O. Whoever is first to line up three in a row (horizontal, vertical or diagonal) wins.

The project consists of 5 steps, each is a separate task. Complete them in order.

Game architecture

Before coding, you need to break the task into parts:

  1. Board — a 3×3 array where each cell is null, 'X' or 'O'
  2. Move — function makeMove(board, row, col, player)
  3. Check winner — function checkWinner(board)'X', 'O' or null
  4. Draw — function isDraw(board)
  5. Game loop — controls player turns and game end
javascript
💬

The board is an array of arrays (3×3 matrix). null means an empty cell.

💡

Hint about rows and columns

board[0][0] — top left corner. board[1][1] — center. board[2][2] — bottom right. The first index is the row, the second is the column.

How to check the winner

You need to check 8 combinations:

  • 3 horizontals (rows 0, 1, 2)
  • 3 verticals (columns 0, 1, 2)
  • 2 diagonals (main and anti)

If all three cells in a line are the same and not null — there is a winner.

javascript
💬

We iterate over all 8 lines and check if all three cells are the same.

Ready? Complete the tasks in order!

Each task builds on the next. When you complete all 5 — you'll have a complete game. Don't peek at the solution right away — try on your own for at least 10–15 minutes.

Comments

Log In or Start to leave a comment.