Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted about 3 years ago

Tic Tac Toe | Next.js

framer-motion, jest, next, styled-components, react-testing-library
Raymart Pamplona•16,040
@pikapikamart
A solution to the Tic Tac Toe game challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


Hello. This is my 25th challenge here at fem and my first challenge into using testing!!

This challenge was fun to do and it is my first time into coding a tic tac toe game as well and I hope I did fine on this one. For the logic of the game, I used the minimax algorithm to get the most optimal move for the AI and since it uses the optimal move, I can't even win :>

As I mentioned, it is my first time using jest or doing testing in general using javascript. For the implementation of the backtrack algorithm, I used a test first approach which I find really nice and i'll be adapting this one for further challenges and I kind of relate now to others saying seeing green light on their test soothes :>

But for the most component in next, I haven't made the same test approach because I don't know how to test them initially and don't know when I should test a component so this is not a consistent one. But hey, I test first again on the new user experience (NUX) and for the grid navigations for keyboard keys!

For the grid itself, initially, those were created using button inside in their own div role="gridcell" inside the role="grid", but at the end, I changed them into just using the div role="gridcell and completely removing the button elements. The reason for this is that I find it confusing as a user when placing a move mark on the grid, because a button have 2 states right, a pressed/toggled and not pressed/toggled, I don't want the user to think that they can undo a move after placing. Adding disabled or aria-pressed on it would be much confusing and mess up the grid navigations. That is why I just use the div role="gridcell" itself as the placement for each move mark with their own sr-only text.

Overall, i'm happy on the outcome but I need to learn more about testing and using it! Another one, maybe adding some threshold for the scores to whether make cpu more smart would be nice, you know, so that we could win:>>

Thanks for checking this one out!

Update.

I added an online mode as well so that everyone could play against different players. I use socket.io on this one. Thank you again!

Code
Loading...

Please log in to post a comment

Log in with GitHub

Community feedback

No feedback yet. Be the first to give feedback on Raymart Pamplona's solution.

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit 1st-party linked stylesheets, and styles within <style> tags.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.