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

Поделиться
HTML-код
  • Опубликовано: 12 сен 2024
  • 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/jav...
    Happy hacking!
    Where you can find me?
    🔗 Links:
    * 🍺 Support free education and buy me a beer: ko-fi.com/adam...
    * 💬 Discord: / discord
    * 📧 Newsletter: www.getrevue.c...
    * ✍️ Blog: dev.to/javascr...
    * 🐦 Twitter: / dev_adamnagy
    * 📷 Instagram: / javascriptacademy

Комментарии • 151

  • @JsAcademyOfficial
    @JsAcademyOfficial  Год назад +3

    New web development tutorial from me: Memory card game using Javascript, HTML, and CSS: 🔥
    ruclips.net/video/xWdkt6KSirw/видео.html

  • @shuvohabib8521
    @shuvohabib8521 2 года назад +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 2 года назад +45

    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 3 года назад +21

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

  • @mspencer3674
    @mspencer3674 3 года назад +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  3 года назад +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 3 года назад

      Did it work? Because I tried but for some reason it didn’t work like idk what I did😭🥲

    • @HopeeM
      @HopeeM 3 года назад

      @@ale4461 just completed everything buh mine ain’t running/working too🤔

    • @JsAcademyOfficial
      @JsAcademyOfficial  3 года назад +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!

  • @TomDoesTech
    @TomDoesTech 3 года назад +9

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

  • @thatindianviewer3110
    @thatindianviewer3110 3 года назад +26

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

    • @JsAcademyOfficial
      @JsAcademyOfficial  3 года назад +2

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

    • @skytutorials3843
      @skytutorials3843 3 года назад +1

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

    • @mantoshtiwari6989
      @mantoshtiwari6989 2 года назад +2

      When I click to the board there is nothing happens

  • @notjev4969
    @notjev4969 3 года назад +6

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

    • @JsAcademyOfficial
      @JsAcademyOfficial  3 года назад

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

  • @sakshinegi394
    @sakshinegi394 2 года назад +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.....👍🏻

  • @manmoderno5274
    @manmoderno5274 Год назад +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 Год назад

      vaya mudu da

    • @nickodagohoy9366
      @nickodagohoy9366 11 месяцев назад

      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.

  • @pratikbawane2165
    @pratikbawane2165 3 года назад

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

    • @JsAcademyOfficial
      @JsAcademyOfficial  3 года назад

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

  • @sukritgarg3175
    @sukritgarg3175 2 года назад +2

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

  • @ngubanezibusiso5154
    @ngubanezibusiso5154 2 года назад +2

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

  • @sherlockholmes3822
    @sherlockholmes3822 Год назад +2

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

  • @user-nd3rn1px3j
    @user-nd3rn1px3j 11 месяцев назад +1

    wow your video is very appriciaement

  • @rachelcoleelliott1519
    @rachelcoleelliott1519 2 года назад +1

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

  • @fabfitforever4934
    @fabfitforever4934 9 месяцев назад

    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.

  • @HopeeM
    @HopeeM 3 года назад +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 2 года назад

      Same here nothing happened only empty box

    • @sakshinegi394
      @sakshinegi394 2 года назад +1

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

  • @olahantonio2561
    @olahantonio2561 2 года назад +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 2 года назад

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

    • @johanhellberg9677
      @johanhellberg9677 2 года назад

      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.

  • @Veysula007
    @Veysula007 Год назад +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  Год назад

      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.

  • @uzbekrussianenglishmovies6571
    @uzbekrussianenglishmovies6571 2 года назад +2

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

  • @neevbadu3611
    @neevbadu3611 Год назад +1

    Awesome Tutorial... Thanks..

  • @oyoxein1825
    @oyoxein1825 10 месяцев назад

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

  • @yashbawa3486
    @yashbawa3486 Год назад

    This format is much better than coding in front ☻

  • @jenneanfrancis5610
    @jenneanfrancis5610 2 года назад +1

    Hi what program did you use to make the game?

    • @pumpk_1712
      @pumpk_1712 2 года назад

      vscode you're welcome prob wont see this tho

  • @balukarthik.ravanam6365
    @balukarthik.ravanam6365 3 месяца назад

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

  • @dungeonpanther
    @dungeonpanther 3 года назад +2

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

  • @thecommandstrike2543
    @thecommandstrike2543 Год назад

    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?

  • @acupioalt
    @acupioalt 7 месяцев назад

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

  • @MightyKingKala
    @MightyKingKala 2 года назад +2

    Thank you for this project

  • @johnnyvo8416
    @johnnyvo8416 2 года назад

    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??

  • @blisterblaster3944
    @blisterblaster3944 Год назад

    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

  • @eskie0681
    @eskie0681 Год назад

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

    • @gabrielavalos1611
      @gabrielavalos1611 11 месяцев назад

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

  • @kvelez
    @kvelez 7 месяцев назад

    Great video.

  • @ryuk11
    @ryuk11 3 года назад +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

  • @abhinavyadav2406
    @abhinavyadav2406 2 года назад +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 2 года назад

      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.

  • @ercumentsengezer9219
    @ercumentsengezer9219 2 года назад

    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 :)

  • @nickodagohoy9366
    @nickodagohoy9366 11 месяцев назад

    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?

  • @mratta583
    @mratta583 5 месяцев назад

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

  • @arnaldoferreira632
    @arnaldoferreira632 2 года назад +3

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

  • @peterokade8199
    @peterokade8199 2 года назад +1

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

  • @mblede
    @mblede Год назад

    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 Год назад

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

  • @kristinamaglov1130
    @kristinamaglov1130 2 года назад

    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  2 года назад +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! 😊

  • @Onaneehsyu9286
    @Onaneehsyu9286 Год назад

    Where is the code for isValidAction at???

  • @JHONYUUI
    @JHONYUUI Год назад

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

  • @kevinpatel03
    @kevinpatel03 2 года назад

    which software did you use

    • @JsAcademyOfficial
      @JsAcademyOfficial  2 года назад

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

  • @anastasiia_idle
    @anastasiia_idle 2 года назад

    why does he use section for button instead of div?

  • @Letsdream16
    @Letsdream16 3 года назад +1

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

    • @JsAcademyOfficial
      @JsAcademyOfficial  3 года назад +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 3 года назад

      @@JsAcademyOfficial ya

    • @JsAcademyOfficial
      @JsAcademyOfficial  3 года назад

      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 3 года назад

      @@JsAcademyOfficial thank you sir

  • @gergokovacs3362
    @gergokovacs3362 2 года назад

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

    • @sukocan1
      @sukocan1 2 года назад +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 2 года назад +2

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

    • @gergokovacs3362
      @gergokovacs3362 Год назад

      @@sukocan1 Thank you!

  • @dibyarajdutta
    @dibyarajdutta 3 года назад

    You Are Awsome Man😍

  • @onyxjohn2132
    @onyxjohn2132 Год назад

    i have it but i cant click and play

  • @user-du5jo1fo3l
    @user-du5jo1fo3l Год назад

    thank you bro

  • @m_____5290
    @m_____5290 3 года назад +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?

  • @ramazanmorina3929
    @ramazanmorina3929 2 года назад

    How do you put it in a website

  • @uniqueprincess6477
    @uniqueprincess6477 2 года назад

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

    • @JsAcademyOfficial
      @JsAcademyOfficial  2 года назад

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

  • @TerrorTarun
    @TerrorTarun Год назад

    Which program is it?

  • @othanhphuoc5033
    @othanhphuoc5033 Год назад

    great job bro

  • @usefulfacts6135
    @usefulfacts6135 2 года назад

    Wat is the software?

  • @pousstatusstudio113
    @pousstatusstudio113 2 года назад

    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  2 года назад

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

  • @gamesbefunn-1330
    @gamesbefunn-1330 Год назад

    what is this app that you are using to code?

  • @gamegen3015
    @gamegen3015 2 года назад

    Mine wont place x or o

  • @yashwardhansingh4213
    @yashwardhansingh4213 Год назад

    Thank You Soooooooooooooooo Much

  • @IT--PRIYADARSHINIM
    @IT--PRIYADARSHINIM 3 года назад +1

    what ide you using?

    • @JsAcademyOfficial
      @JsAcademyOfficial  3 года назад

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

    • @JsAcademyOfficial
      @JsAcademyOfficial  3 года назад

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

  • @sakshinegi394
    @sakshinegi394 2 года назад

    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 2 года назад

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

    • @cesairecivil3227
      @cesairecivil3227 2 года назад +1

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

    • @sakshinegi394
      @sakshinegi394 2 года назад

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

    • @sakshinegi394
      @sakshinegi394 2 года назад

      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.

  • @maddex6664
    @maddex6664 2 года назад

    can i copy and paste it

  • @lindaofori8827
    @lindaofori8827 2 года назад

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

  • @addypash880
    @addypash880 2 года назад

    I have taken the source code but still its not working

    • @JsAcademyOfficial
      @JsAcademyOfficial  2 года назад

      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

  • @dienasormosquito3259
    @dienasormosquito3259 2 года назад

    I've been trying my best to copy the code sir..but it won't run🤧🤧🤧🤧🤧😭😭😭😭

    • @JsAcademyOfficial
      @JsAcademyOfficial  2 года назад

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

  • @Yael1909
    @Yael1909 3 месяца назад

    Buen vìdeo!

  • @OpticalHer0
    @OpticalHer0 2 года назад

    Which VS Code theme do you use?

    • @JsAcademyOfficial
      @JsAcademyOfficial  2 года назад +1

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

    • @OpticalHer0
      @OpticalHer0 2 года назад

      @@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  2 года назад +1

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

  • @rangdell4501
    @rangdell4501 Год назад

    not working

  • @IamShubhamKumarrr
    @IamShubhamKumarrr 2 года назад

    I Think You Need to Make A Single Player

  • @mathsgames1074
    @mathsgames1074 2 года назад

    thank you

  • @Zephyr.cc_
    @Zephyr.cc_ 2 года назад

    Im getting errors but dont know why

  • @MsPhTutorials
    @MsPhTutorials 2 года назад

    How To Place Ads On It??

    • @JsAcademyOfficial
      @JsAcademyOfficial  2 года назад

      Hi Reah!
      What do you want to place ads on? The game itself?

  • @sonulil
    @sonulil Год назад

    hello sir i am use this game in my website

  • @inwarhammer8494
    @inwarhammer8494 2 года назад

    Well, how to keep the record for scores ?

    • @JsAcademyOfficial
      @JsAcademyOfficial  2 года назад +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 2 года назад

      @@JsAcademyOfficial thanks for the reply !❤️

  • @flick2.099
    @flick2.099 2 года назад

    1:50

  • @ayandas5730
    @ayandas5730 2 года назад

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

  • @tameronlevijohn3468
    @tameronlevijohn3468 3 года назад

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

    • @JsAcademyOfficial
      @JsAcademyOfficial  3 года назад +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 3 года назад

      @@JsAcademyOfficial thanks a lot ❤️👌🏻

  • @АкадемикА-л5я
    @АкадемикА-л5я 3 года назад

    Keep making video please

    • @JsAcademyOfficial
      @JsAcademyOfficial  3 года назад

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

  • @musichype2003
    @musichype2003 Год назад

    where did i went wrong?

  • @littlekidkarl4727
    @littlekidkarl4727 Год назад +1

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

  • @notadeelplayz6771
    @notadeelplayz6771 2 года назад

    Create a Detailed Version

  • @altravels7426
    @altravels7426 2 года назад

    t y p e

  • @espertor
    @espertor 2 года назад

    Você é brasileiro né kkkkjj

  • @moviess7910
    @moviess7910 2 года назад

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

  • @rangdell4501
    @rangdell4501 Год назад

    help

  • @musicboss4084
    @musicboss4084 Год назад

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

  • @stopstalkingme2023
    @stopstalkingme2023 Год назад

    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  Год назад

      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 3 года назад

    please reply as soon as possible