Create a simple tic tac toe game using HTML, CSS, JavaScript

SdĂ­let
VloĆŸit
  • čas pƙidĂĄn 22. 05. 2021
  • In today's video, I'll show you how you can create a simple tic-tac-toe game using HTML, CSS, and JavaScript.
    Please leave feedback in the comment section about this new style of video, I hope you will enjoy this kind of content.
    You can request video tutorials, and ask for explanation videos of your choice in the comment section.
    Source code: github.com/javascriptacademy-...
    Happy hacking!
    Where you can find me?
    🔗 Links:
    * đŸș Support free education and buy me a beer: ko-fi.com/adamnagy
    * 💬 Discord: / discord
    * 📧 Newsletter: www.getrevue.co/profile/dev_a...
    * ✍ Blog: dev.to/javascriptacademy
    * 🐩 Twitter: / dev_adamnagy
    * đŸ“· Instagram: / javascriptacademy

Komentáƙe • 151

  • @JsAcademyOfficial
    @JsAcademyOfficial  Pƙed rokem +3

    New web development tutorial from me: Memory card game using Javascript, HTML, and CSS: đŸ”„
    czcams.com/video/xWdkt6KSirw/video.html

  • @shuvohabib8521
    @shuvohabib8521 Pƙed 2 lety +22

    Thanks for this, but it'd be better to watch, if you'd create the game keeping the browser preview side-by-side.

  • @vimalsinghgaur
    @vimalsinghgaur Pƙed 2 lety +46

    You should time to time show the page/screen to have an idea of step by step progress of the game screen. This sustain the interest of beginners like me.

  • @wisdomelue
    @wisdomelue Pƙed 2 lety +21

    thank you, but i kinda prefer you writing the code, helps us grasp better

  • @notjev4969
    @notjev4969 Pƙed 3 lety +6

    Thank you so much! I needed this for a project and now I understand everything!

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 3 lety

      Awesome news! I’m glad you like it and found it useful :)

  • @sakshinegi394
    @sakshinegi394 Pƙed 2 lety +1

    Thanku sr it is running now its my first project hurrah!!đŸ„łđŸ„łAND I also design snake game today it is also running smoothly đŸ„łđŸ„ł ur video motivated me to engross in the things like this.....đŸ‘đŸ»

  • @mspencer3674
    @mspencer3674 Pƙed 3 lety +6

    It’s late where i’m currently at but i’m 100% doing this tomorrow after work! Thank you for the content, keep it up.
    Kind regards.

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 3 lety +1

      It’s late here too, but I was so excited to share it with you all, I couldn’t wait more so shared it asap :).
      I hope it will make you happy tomorrow :)
      Best wishes

    • @ale4461
      @ale4461 Pƙed 3 lety

      Did it work? Because I tried but for some reason it didn’t work like idk what I did😭đŸ„Č

    • @HopeeM
      @HopeeM Pƙed 2 lety

      @@ale4461 just completed everything buh mine ain’t running/working toođŸ€”

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 2 lety +1

      Try to clone the repository and compare it with your own code. You can find the link in the description of the video :) it must be a typo in your code . Have a nice day!

  • @sukritgarg3175
    @sukritgarg3175 Pƙed 2 lety +2

    I dont have enough words to thank you for this sir....

  • @TomDoesTech
    @TomDoesTech Pƙed 3 lety +9

    Nice tutorial! Looks like a fun game to make :)

  • @pratikbawane2165
    @pratikbawane2165 Pƙed 3 lety

    I'm your 1000th subscriber!
    Congrats for 1k subs....

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 3 lety

      Welcome to the academy my friend! Thanks for choosing to subcribe :)

  • @thatindianviewer3110
    @thatindianviewer3110 Pƙed 3 lety +26

    This is the best explanation and the easiest implementation I've ever seen for a tic tac toe game

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 3 lety +2

      Thanks for the kind words. I’m glad you found it useful. 😊

    • @skytutorials3843
      @skytutorials3843 Pƙed 2 lety +1

      Then you havent seen much! This is so extended!! Not the Best!

    • @mantoshtiwari6989
      @mantoshtiwari6989 Pƙed rokem +2

      When I click to the board there is nothing happens

  • @ngubanezibusiso5154
    @ngubanezibusiso5154 Pƙed 2 lety +2

    Thanks so much....the explanation was great... I also added some HTML imojis

  • @sherlockholmes3822
    @sherlockholmes3822 Pƙed rokem +2

    Hello, you should showcase the results time to time, while building something

  • @manmoderno5274
    @manmoderno5274 Pƙed rokem +3

    For those having issues, check for typos and use the debug console. I do believe that this can done in an even simpler manor.

    • @littlekidkarl4727
      @littlekidkarl4727 Pƙed rokem

      vaya mudu da

    • @nickodagohoy9366
      @nickodagohoy9366 Pƙed 9 měsĂ­ci

      I tried this on sololearn(mobile app that has courses and a code playground) but the player change dont work. Everytime i click on a tile, only X displays until X wins. Also, the display for the turns dont work also. Just Player X turn. Apart from that problem, it seems to be working, even the reset button works.

  • @thecommandstrike2543
    @thecommandstrike2543 Pƙed rokem

    Hi! I’m having trouble with the buttons not working. There isn’t anything in the console and I checked for typos. I did notice something call quirks mode though. Should I disable it?

  • @yashbawa3486
    @yashbawa3486 Pƙed rokem

    This format is much better than coding in front ☻

  • @user-nd3rn1px3j
    @user-nd3rn1px3j Pƙed 9 měsĂ­ci +1

    wow your video is very appriciaement

  • @johnnyvo8416
    @johnnyvo8416 Pƙed 2 lety

    please help me. I tried to rewrite this code, but my const announce = (type) => {
    } is having a swiggle error. It says it is expecting a `default case` within the whole body. How can I fix this??

  • @rachelcoleelliott1519
    @rachelcoleelliott1519 Pƙed 2 lety +1

    Why did you add the js link at the top of the index.html instead of at the bottom?

  • @oyoxein1825
    @oyoxein1825 Pƙed 8 měsĂ­ci

    i have a problem the player donÂŽt change when i click for the first time

  • @fabfitforever4934
    @fabfitforever4934 Pƙed 7 měsĂ­ci

    very excited for a shorter video for tic tac toe but does this make it so your playing by yourself? & im not sure why my X or O wont show up when i click the tiles. I followed everything and watched the video 2x to make sure but still not working.

  • @MightyKingKala
    @MightyKingKala Pƙed 2 lety +2

    Thank you for this project

  • @neevbadu3611
    @neevbadu3611 Pƙed rokem +1

    Awesome Tutorial... Thanks..

  • @dibyarajdutta
    @dibyarajdutta Pƙed 2 lety

    You Are Awsome Man😍

  • @blisterblaster3944
    @blisterblaster3944 Pƙed rokem

    hello just found this and i'm planning to use this source code but i have a question. how can i save the png images? I don't know how? thank you

  • @nickodagohoy9366
    @nickodagohoy9366 Pƙed 9 měsĂ­ci

    I tried this on sololearn(mobile app that has courses and a code playground) but the player change dont work. Everytime i click on a tile, only X displays until X wins. Also, the display for the turns dont work also. Just Player X turn. Can anybody help?

  • @kvelez
    @kvelez Pƙed 5 měsĂ­ci

    Great video.

  • @yashwardhansingh4213
    @yashwardhansingh4213 Pƙed rokem

    Thank You Soooooooooooooooo Much

  • @JHONYUUI
    @JHONYUUI Pƙed rokem

    When I click on one of the grid squares it does nothing can someone please help me

  • @othanhphuoc5033
    @othanhphuoc5033 Pƙed rokem

    great job bro

  • @balukarthik.ravanam6365
    @balukarthik.ravanam6365 Pƙed měsĂ­cem

    Can I modify it so that I can count the number of wins for a person until they refresh the page

  • @ercumentsengezer9219
    @ercumentsengezer9219 Pƙed 2 lety

    Hey! i Wonder what is difference between Visual code and Visual studio! When script this with visual studio i can play but, Visual studio I can *not* ! Do know the answer ? And i have to thanks for clear instruction :)

  • @user-du5jo1fo3l
    @user-du5jo1fo3l Pƙed rokem

    thank you bro

  • @anastasiia_idle
    @anastasiia_idle Pƙed rokem

    why does he use section for button instead of div?

  • @mathsgames1074
    @mathsgames1074 Pƙed 2 lety

    thank you

  • @ramazanmorina3929
    @ramazanmorina3929 Pƙed 2 lety

    How do you put it in a website

  • @arnaldoferreira632
    @arnaldoferreira632 Pƙed 2 lety +3

    Thanks. You're really good at clarifying the concepts. I followed everything and built mine too.

  • @Onaneehsyu9286
    @Onaneehsyu9286 Pƙed rokem

    Where is the code for isValidAction at???

  • @Veysula007
    @Veysula007 Pƙed rokem +1

    It's probably a stupid question but I am a new one and I wonder how do you manage to start the actual game because I have the javascript/html/css files but I can't run them in order to test it out?

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed rokem

      There’s no thing like a stupid question😉 if everything is linked correctly inside the files. You should only need to open the index.html file with the browser of your choice.

  • @ryuk11
    @ryuk11 Pƙed 3 lety +4

    That was wonderful video. Can you plz make a game where bomb falls ramdom on the ground and character have to Dodge ♄♄
    using html CSS and java

  • @TerrorTarun
    @TerrorTarun Pƙed rokem

    Which program is it?

  • @onyxjohn2132
    @onyxjohn2132 Pƙed rokem

    i have it but i cant click and play

  • @gamegen3015
    @gamegen3015 Pƙed 2 lety

    Mine wont place x or o

  • @acupioalt
    @acupioalt Pƙed 5 měsĂ­ci

    thank you so much Mr JavaScript Academy! It helped me so so much!
    -XOXO 13 year old girl

  • @m_____5290
    @m_____5290 Pƙed 2 lety +1

    When the game is won/is a tie i dont want the text saying player x's turn for example, how would i change that in the javascript?

  • @maddex6664
    @maddex6664 Pƙed 2 lety

    can i copy and paste it

  • @peterokade8199
    @peterokade8199 Pƙed 2 lety +1

    so the const winningConditions are like conditionals that will show all the possible ways to win.

  • @Yael1909
    @Yael1909 Pƙed měsĂ­cem

    Buen vĂŹdeo!

  • @usefulfacts6135
    @usefulfacts6135 Pƙed 2 lety

    Wat is the software?

  • @gergokovacs3362
    @gergokovacs3362 Pƙed 2 lety

    Nice work and explanation, thank you.
    Could someone please explain me, where does the "index" parameter get it value from?

    • @sukocan1
      @sukocan1 Pƙed rokem +3

      If you are asking the line
      tiles.forEach( (tile, index) =>{ ................
      forEach is a method executes a function for each array element. You can rewrite it as
      tiles.forEach( (boom, bang) => {.......... or whatever you like. It does not get the parameter from somewhere else. The first parameter here boom/tile executes on the element. Second one bang/index starts from the 0 index and gives you the index number.
      From MDN:
      const array1 = ['a', 'b', 'c'];
      array1.forEach(element => console.log(element));
      // expected output: "a"
      // expected output: "b"
      // expected output: "c"
      const array1 = ['a', 'b', 'c'];
      array1.forEach(element => console.log(index));
      // expected output: "0"
      // expected output: "1"
      // expected output: "2"

    • @sukocan1
      @sukocan1 Pƙed rokem +2

      And in case I got your question wrong, he explains how we get the value from clicked action at 06:00

    • @gergokovacs3362
      @gergokovacs3362 Pƙed rokem

      @@sukocan1 Thank you!

  • @mratta583
    @mratta583 Pƙed 3 měsĂ­ci

    I write the whole code but it didn't work 😱

  • @jenneanfrancis5610
    @jenneanfrancis5610 Pƙed 2 lety +1

    Hi what program did you use to make the game?

    • @pumpk_1712
      @pumpk_1712 Pƙed rokem

      vscode you're welcome prob wont see this tho

  • @abhinavyadav2406
    @abhinavyadav2406 Pƙed 2 lety +1

    Thanks sir for making this project but i have a problem that when i am trying to click at grid it is not clicking

    • @wlsdldu
      @wlsdldu Pƙed rokem

      You could try to see if lines 119~124 are written correctly, as those pieces of code are the ones that dictate what should happen if you click on the screen.
      Double checking for capitalization errors throughout your Javascript could also help as well! Mine wasn't working the first time so I had to go in and recheck each line for errors, and that fixed my issues.

  • @olahantonio2561
    @olahantonio2561 Pƙed 2 lety +4

    Hi! What is the right method to learn the concepts that are required to know to code? I mean should i just copy your code and try to understand it? because i could not figure out how to write the code myself for this simple game

    • @hammerofolympia3716
      @hammerofolympia3716 Pƙed 2 lety

      Same here buddy i was thinking of some convoluted if else statement hell.

    • @johanhellberg9677
      @johanhellberg9677 Pƙed 2 lety

      What’s worked well for me is to watch it once with increased speed, then watch it again while stopping the video and writing each line of code. Just absorb some of the knowledge. Then try to thing if something I can add or change.

  • @sonulil
    @sonulil Pƙed rokem

    hello sir i am use this game in my website

  • @flick2.099
    @flick2.099 Pƙed 2 lety

    1:50

  • @uzbekrussianenglishmovies6571

    I wrote what you specified in vs code, chrome does not work, javascript file does not work

  • @mblede
    @mblede Pƙed rokem

    Hello! I really loved your tutorial and I followed it step by step, but I have a problem: when opening the index.html file to try out the game I click on the tiles and nothing happens. What am I missing or doing wrong?

    • @Mahmoud_176
      @Mahmoud_176 Pƙed rokem

      Check if u linked your "JavaScript" file in your"HTML file"

  • @Letsdream16
    @Letsdream16 Pƙed 3 lety +1

    How can we open this in separate page on website so it runs automatically like playing online without code?

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 3 lety +1

      Hi!
      I'm not sure I understand what you mean. Do you mean that is this code available in online tools like codepen?

    • @Letsdream16
      @Letsdream16 Pƙed 3 lety

      @@JsAcademyOfficial ya

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 3 lety

      here is your link :)
      Hope it helps :) I'll include it in future videos :)
      codesandbox.io/s/github/javascriptacademy-stash/tic-tac-toe

    • @Letsdream16
      @Letsdream16 Pƙed 3 lety

      @@JsAcademyOfficial thank you sir

  • @kristinamaglov1130
    @kristinamaglov1130 Pƙed 2 lety

    When I click on game nothing is happening.It doesn't want to show X or 0 on table-What am I supposed to do?

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 2 lety +1

      Hi Kristina!
      Must probably a typo or something with the event handlers. Please take a look at the source code in the description.
      Happy hacking! 😊

  • @IamShubhamKumarrr
    @IamShubhamKumarrr Pƙed 2 lety

    I Think You Need to Make A Single Player

  • @user-ww7xz3pr9w
    @user-ww7xz3pr9w Pƙed 3 lety

    Keep making video please

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 3 lety

      Thanks, I try my best to bring content as soon as possible. I’m glad you find it useful

  • @kevinpatel03
    @kevinpatel03 Pƙed 2 lety

    which software did you use

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 2 lety

      If you mean the code editor it is visual studio code. The browser is Brave

  • @lindaofori8827
    @lindaofori8827 Pƙed 2 lety

    It isn't working there a problem at tile.classlist.add('player$(currentPlayer)');

  • @dungeonpanther
    @dungeonpanther Pƙed 2 lety +2

    If i click on the boxes the x or o are not occurring can you tell what is the problem

  • @uniqueprincess6477
    @uniqueprincess6477 Pƙed 2 lety

    Sir output show player x turn and reset..
    I click reset bt it's not work

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 2 lety

      Make sure you not have a typo in the classnames both in js and html

  • @eskie0681
    @eskie0681 Pƙed rokem

    I followed everything but for some reason the board will not show up for me, do you know why?

    • @gabrielavalos1611
      @gabrielavalos1611 Pƙed 9 měsĂ­ci

      For me it was because I had in all instead of in the index.html

  • @Zephyr.cc_
    @Zephyr.cc_ Pƙed rokem

    Im getting errors but dont know why

  • @rangdell4501
    @rangdell4501 Pƙed rokem

    not working

  • @HopeeM
    @HopeeM Pƙed 2 lety +5

    Kindly assist what could be the problem mine ain’t working did the coding right buh the X’s and O’s not appearing when I click đŸ€”

    • @sakshinegi394
      @sakshinegi394 Pƙed 2 lety

      Same here nothing happened only empty box

    • @sakshinegi394
      @sakshinegi394 Pƙed 2 lety +1

      I changed background color first after correction of js code then it works..

  • @pousstatusstudio113
    @pousstatusstudio113 Pƙed 2 lety

    Sir I am using vs code live server hut it is not working sir, when I am clicking on it , It is not responding

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 2 lety

      Hi POU!
      Must be a typo in the event handlers or the html ids. Please refer to the example code in the description! Cheers

  • @OpticalHer0
    @OpticalHer0 Pƙed 2 lety

    Which VS Code theme do you use?

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 2 lety +1

      Hi!
      It is One monokai theme
      marketplace.visualstudio.com/items?itemName=azemoh.one-monokai
      Also I use material Icon theme

    • @OpticalHer0
      @OpticalHer0 Pƙed 2 lety

      @@JsAcademyOfficial by The way, very nice code! It is clean and explained very well. Now I'm trying to do this little project in Vue.js. Thank you

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 2 lety +1

      Thanks for the feedback Luigi!
      Good luck for your VueJs implementation! 😊

  • @notadeelplayz6771
    @notadeelplayz6771 Pƙed 2 lety

    Create a Detailed Version

  • @IT--PRIYADARSHINIM
    @IT--PRIYADARSHINIM Pƙed 3 lety +1

    what ide you using?

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 3 lety

      It is vscode with oneMonokai colr theme extension and material icons pack

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 3 lety

      You can get it from here:
      code.visualstudio.com
      Happy coding!

  • @gamesbefunn-1330
    @gamesbefunn-1330 Pƙed rokem

    what is this app that you are using to code?

  • @sakshinegi394
    @sakshinegi394 Pƙed 2 lety

    I code all the things right but when I run the code it shows in chrome localhost:8080 refused to connect
    Pls tell me what to do I need this to run

    • @sakshinegi394
      @sakshinegi394 Pƙed 2 lety

      Now its fixed but I cant play game nothing is appears in box

    • @cesairecivil3227
      @cesairecivil3227 Pƙed 2 lety +1

      Mine does the same thing, how dod you get it to work?

    • @sakshinegi394
      @sakshinegi394 Pƙed 2 lety

      @@cesairecivil3227 I deleted vscode file from the folder and then run again it works..

    • @sakshinegi394
      @sakshinegi394 Pƙed 2 lety

      When this local host error occurs it do the same thing..and after that I there are some mistakes in my js code thrn I rechecked it. Now it is completely working.

  • @addypash880
    @addypash880 Pƙed 2 lety

    I have taken the source code but still its not working

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 2 lety

      Here is the codesandbox of the repository and it is workind 100%.
      See what is different in your code:
      codesandbox.io/embed/pensive-clarke-kvccp?codemirror=1

  • @inwarhammer8494
    @inwarhammer8494 Pƙed 2 lety

    Well, how to keep the record for scores ?

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 2 lety +1

      I’d add an object with playerX and playerO fields and itit it with 0. And if a player wins increment the corresponding valu

    • @inwarhammer8494
      @inwarhammer8494 Pƙed 2 lety

      @@JsAcademyOfficial thanks for the reply !❀

  • @tameronlevijohn3468
    @tameronlevijohn3468 Pƙed 2 lety

    Thankful for the video but my code is same as yours and it's still not working

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 2 lety +1

      Hi!
      There must be a typo in your implementation. Here is the interactive online playground of the project, compare it with your code, hope it helps:
      codesandbox.io/s/hk8bi

    • @tameronlevijohn3468
      @tameronlevijohn3468 Pƙed 2 lety

      @@JsAcademyOfficial thanks a lot â€ïžđŸ‘ŒđŸ»

  • @musichype2003
    @musichype2003 Pƙed rokem

    where did i went wrong?

  • @MsPhTutorials
    @MsPhTutorials Pƙed 2 lety

    How To Place Ads On It??

  • @dienasormosquito3259
    @dienasormosquito3259 Pƙed 2 lety

    I've been trying my best to copy the code sir..but it won't runđŸ€§đŸ€§đŸ€§đŸ€§đŸ€§đŸ˜­đŸ˜­đŸ˜­đŸ˜­

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed 2 lety

      Feel free to download the source code from the description and compare it to yours.

  • @moviess7910
    @moviess7910 Pƙed 2 lety

    does somebody know how to rewrite the code so that it is 5x5 and you need 4 to win?

  • @ayandas5730
    @ayandas5730 Pƙed 2 lety

    Simply just a copy of Web Dev Simplified's code with just a few color changes.

  • @altravels7426
    @altravels7426 Pƙed 2 lety

    t y p e

  • @rangdell4501
    @rangdell4501 Pƙed rokem

    help

  • @espertor
    @espertor Pƙed 2 lety

    VocĂȘ Ă© brasileiro nĂ© kkkkjj

  • @littlekidkarl4727
    @littlekidkarl4727 Pƙed rokem +1

    hey bro paradesi payaley unnala project poiduchu please make only html illana aduchuduvein 😡

  • @musicboss4084
    @musicboss4084 Pƙed rokem

    i copied you at every point, but my game is not working

  • @stopstalkingme2023
    @stopstalkingme2023 Pƙed rokem

    Atleast try to show the progress step by step while displaying it in the browser. It seems like u r in a hurry to catch a bus or something. Not useful for beginners.

    • @JsAcademyOfficial
      @JsAcademyOfficial  Pƙed rokem

      Thanks for the feedback, the aim is to have a brief video by cutting out writing out the code itself, but I agree that I should pay more attention to show the step-bystep progress int he browser.

  • @dungeonpanther
    @dungeonpanther Pƙed 2 lety

    please reply as soon as possible