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:
- Board — a 3×3 array where each cell is
null,'X'or'O' - Move — function
makeMove(board, row, col, player) - Check winner — function
checkWinner(board)→'X','O'ornull - Draw — function
isDraw(board) - Game loop — controls player turns and game end
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.
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.