DEV Community

Cover image for Tic Tac Toe โ€“ A Classic Game Reimagined in JavaScript
MOHIT SHARMA
MOHIT SHARMA

Posted on

Tic Tac Toe โ€“ A Classic Game Reimagined in JavaScript

๐Ÿง  Tic Tac Toe โ€“ A Classic Game Reimagined in JavaScript

๐Ÿ“Œ Live Demo: Play Now

๐Ÿ—‚๏ธ Source Code: GitHub Repo

๐ŸŽ“ Part of My Learning Journey: Learning Curve Showcase


๐ŸŽฏ Project Overview

The Tic Tac Toe Game is one of the foundational JavaScript projects I built as part of my frontend learning journey. It combines DOM manipulation, game logic, and conditional rendering to deliver a fun and interactive browser-based game.

It supports both:

  • ๐Ÿ‘ฅ Two-player mode
  • ๐Ÿค– Play against the bot (single-player mode)

This project is part of my learning-curve initiative where I build real projects to reinforce key frontend concepts.


๐Ÿงฉ Features

  • โœ… 3ร—3 interactive grid
  • ๐Ÿ”„ Turn-based play with automatic switching
  • ๐Ÿค– Single-player mode with a basic bot
  • ๐Ÿง  Win and draw detection
  • ๐Ÿ” "New Game" button to reset
  • ๐Ÿ–ฅ๏ธ Responsive layout for different screen sizes
  • ๐Ÿ’ก Status indicator (shows turn, win, or draw)

๐Ÿ› ๏ธ Tech Stack

  • HTML โ€“ structure of the board and UI
  • CSS โ€“ styling, layout, and responsiveness
  • JavaScript โ€“ logic, state handling, interactivity

๐Ÿง  Key Learnings

Hereโ€™s what I learned and practiced through this project:

  1. DOM Manipulation

    Handling element selection, updating content, and applying styles dynamically using JavaScript.

  2. Game State Management

    Tracking game status (win/draw/turns) using arrays, conditions, and functions.

  3. Event Handling

    Using addEventListener for cell clicks, and updating UI based on logic.

  4. Separation of Concerns

    Writing modular code โ€” separating game logic, UI updates, and event handlers.

  5. Implementing a Basic Bot

    I added a simple bot that selects a random empty cell after the player's move. This introduced me to conditional AI logic.


๐Ÿงช How It Works

  • The board is a 3ร—3 grid of clickable cells.
  • Two modes are supported: Player vs Player or Player vs Bot.
  • On each turn:
    • The player's symbol (X or O) is added to the clicked cell.
    • The game checks for a win using predefined winning patterns.
    • If no win and the board is full, it's a draw.
  • In bot mode, the computer auto-selects a random empty cell.
  • Clicking "New Game" resets the board and status.

๐Ÿš€ Live Project

You can play it right now on GitHub Pages:

๐ŸŽฎ Play Tic Tac Toe


๐Ÿ“‚ Explore the Code

The full source code is available in my GitHub repo. Feel free to explore, fork, or suggest improvements:

๐Ÿ”— Tic Tac Toe โ€“ GitHub Repository


๐Ÿ”ฎ Future Enhancements

Some possible upgrades I plan to work on:

  • ๐Ÿ”Š Add sound effects for clicks and wins
  • ๐ŸŒ— Dark/light mode toggle
  • ๐Ÿง  Improve bot using Minimax algorithm (make it unbeatable)
  • ๐Ÿ“Š Track X/O scores across rounds
  • ๐ŸŽจ Add animations or themes for visual enhancement

๐Ÿ›ค๏ธ Part of My Learning Curve Journey

This project is part of my learning-curve series โ€” a self-designed roadmap where I learn development by building real-world projects. You can explore other projects here:

๐Ÿ”— https://mohit-sharma-dadhich.github.io/learning-curve/#about


๐Ÿ™Œ Final Thoughts

Recreating this simple yet iconic game helped me gain confidence in:

  • Structuring logic
  • Handling user interactions
  • Thinking about UI/UX
  • Working with browser events

Itโ€™s a small step, but every step adds up.

If you're learning JavaScript โ€” build something. Even Tic Tac Toe can teach you a lot.


Thanks for reading! Feel free to leave feedback or fork the repo if you want to expand this game with your own ideas!

Top comments (0)