How to Build Connect 4 with Javascript HTML CSS

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.ย. 2024

ความคิดเห็น • 36

  • @Speed-TV
    @Speed-TV 9 หลายเดือนก่อน +7

    Upgrades:
    - 12:47 instead of setting currentColumns there, you can set it empty and under the board.push(row) you can say currColumns.push(5)
    - You can set the win text to say "Red Turn" and "Yellow Turn" in the setPiece function after setting the currPlayer

  • @LeoCaseiro
    @LeoCaseiro 2 ปีที่แล้ว +8

    If you add the css property `box-sizing: border-box;`, you won't need to change the widht/height after adding a border.

  • @LeoCaseiro
    @LeoCaseiro 2 ปีที่แล้ว +6

    I really enjoyed the way you explain the algorithms with drawing! Please keep doing it! It is really good!!!

  • @IsaacJrDevelops
    @IsaacJrDevelops ปีที่แล้ว +1

    Your explanation of the sliding window concept helped me find value in studying DS&A. Keep up the great work!

  • @nicholasbarton3184
    @nicholasbarton3184 ปีที่แล้ว +2

    Hey thank you so much for making this video. I'm trying to make a more complex version of this for my portfolio. As a beginner though I do wish this was a bit more "beginner" friendly. You take time to explain the overarching ideas but when it comes to the coding itself you go really fast - at least for me haha. Would have been great if you explained why you're doing what you're doing while coding - but maybe that would have been frustrating for people more experienced.

    • @KennyYipCoding
      @KennyYipCoding  ปีที่แล้ว

      Yep, as you mentioned, there are people who have different level of experience. I generally define beginner as someone who recently learned how to program in JavaScript (functions, loops, arrays, etc). Definitely take your time when following along, pause the video, go back, so that you fully understand every line of code!

  • @Jjfddsiure
    @Jjfddsiure ปีที่แล้ว +2

    Im just a beginner, but I think this is the best connect four code I have found on youtube and also very well explained 👏

  • @hiumanyam2952
    @hiumanyam2952 10 หลายเดือนก่อน +1

    Thank you for the great video, I came from another connect four tutorial, your way of coding is beautiful!

  • @birdyperch
    @birdyperch ปีที่แล้ว +2

    Thank you so much! this was super helpful

  • @ayojaydeee8910
    @ayojaydeee8910 2 ปีที่แล้ว

    Bro you’re a legend. It’s simple but to the point, and you do a good job explaining! I can tweak this and modify it to my existing projects. Thank you

    • @KennyYipCoding
      @KennyYipCoding  2 ปีที่แล้ว

      glad you found the tutorial helpful!

  • @suryaprakash-sh5bf
    @suryaprakash-sh5bf ปีที่แล้ว +1

    Thanks for your explanation learned a lot of concepts

  • @EdzhonsG59
    @EdzhonsG59 2 ปีที่แล้ว +2

    Can you please tell how to make "Try again" for the game. I try to clear the board and make it clickable again, but it doesn't happen.

    • @GRMREAP3R97
      @GRMREAP3R97 2 ปีที่แล้ว

      I was trying to do the same; maybe add a HTML button and call the setGame function with that? We'd also need a click event listener there!

  • @KennyYipCoding
    @KennyYipCoding  2 ปีที่แล้ว +2

    Check out the playlist of web project tutorials here!
    th-cam.com/play/PLnKe36F30Y4bLhA-st9sC4ZthyV7nsL2Q.html
    Got a tutorial suggestion? Let me know down below!

  • @Loghinesko
    @Loghinesko ปีที่แล้ว

    At 10:12, when you used the keyword "this", you mean the 'tile' object, right? I'm learning the "this" keyword in js right now.

  • @lenlen1405
    @lenlen1405 9 หลายเดือนก่อน

    I am trying to add a “restart button” for this .. I’m unable to make it to work :(

  • @KennyYipCoding
    @KennyYipCoding  2 ปีที่แล้ว +2

    how to code WORDLE: th-cam.com/video/ckjRsPaWHX8/w-d-xo.html
    how to code SUDOKU: th-cam.com/video/S4uRtTb8U-U/w-d-xo.html
    how to code 2048: th-cam.com/video/XM2n1gu4530/w-d-xo.html

  • @DougDeLuca-xh1cz
    @DougDeLuca-xh1cz ปีที่แล้ว

    What would you recommend doing if it's a tie in the game?

  • @user-gg2hb5pm6d
    @user-gg2hb5pm6d 2 ปีที่แล้ว

    this code doesnt end, as it tells you who won but you can still add counters, whys that ?

  • @GRMREAP3R97
    @GRMREAP3R97 2 ปีที่แล้ว

    Could you explain why the click event listener went inside the setGame function? I thought it was only for setting the game by adding the rows and cols; and their corresponding HTML elements!

    • @KennyYipCoding
      @KennyYipCoding  2 ปีที่แล้ว

      So when our webpage loads, the setGame function is called. This function is where we put the code to initialize the game with. So every tile we create, we set a click event listener for it. We are not creating a function here, but instead binding a function to the tile when it is clicked on. Without this, clicking on the tile does nothing.

  • @seasidesuitesandhotel1258
    @seasidesuitesandhotel1258 ปีที่แล้ว

    There is a small glitch, the game doesn't recognize four in a row from the bottom left corner when the four consecutive pieces go ups from left to right.

    • @KennyYipCoding
      @KennyYipCoding  ปีที่แล้ว

      Are you sure you didn’t make an error on your part?
      You can try it here: www.kennyyipcoding.com/Connect4/

  • @LizMyers
    @LizMyers 2 ปีที่แล้ว

    Kenny, thanks very much for this GREAT SERIES. Quick Question: how do we make this a 2-player game online? I posted this to a website and tested on a second device and the problem is the two instances function independently. I mean when player 1 makes a move - this is not updated on the second screen. How do I fix this? Thanks in advance - Liz

    • @KennyYipCoding
      @KennyYipCoding  2 ปีที่แล้ว +1

      Hi Liz,
      Turning this into a 2 player game would require you to learn a bit of computer networking to connect 2 instances of the game so that they can communicate and play with one another. (A tutorial on how to create a simple chatroom using a web socket may help with this) After you've figured that one out, you need to figure out how to create isolated rooms with different web links so that only 2 people can interact with a single instance of the game. Otherwise, you'd have multiple people trying to play on a single 2-player connect4 board,

    • @LizMyers
      @LizMyers 2 ปีที่แล้ว

      @@KennyYipCoding Thanks for the prompt reply and concise answer. I get it. You're a terrific teacher - please keep up the good work!

  • @vnm_8945
    @vnm_8945 10 หลายเดือนก่อน +1

    I could never do this alone. :(

  • @CSKanhaiyaShivpuri
    @CSKanhaiyaShivpuri 7 หลายเดือนก่อน

    Nice video

  • @pravachanpatra4012
    @pravachanpatra4012 ปีที่แล้ว +1

    5:43

  • @MrDragonboy88
    @MrDragonboy88 ปีที่แล้ว

    How do you append

  • @early991
    @early991 ปีที่แล้ว

    So connect 4 isn't as easy to code as I thought (for me).
    Back to studying so I can get my head round it and be able to think that's what I should write

    • @KennyYipCoding
      @KennyYipCoding  ปีที่แล้ว

      Perhaps take a look at my tutorial on tic tac toe or rock paper scissors. Might be easier to start with.

  • @co-op566
    @co-op566 ปีที่แล้ว

    Can you please tell me how to make a "Draw or tie" in this game?

    • @KennyYipCoding
      @KennyYipCoding  ปีที่แล้ว

      Should be simple. Just keep an int counter for the number of turns and increment it every time a player places a piece. If the number of turns == 7*6 (the number of slots) and there’s no winner, then it’s a tie