How To Build A Simple Card Game With JavaScript

Поделиться
HTML-код
  • Опубликовано: 6 сен 2024

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

  • @___-jh7ys
    @___-jh7ys 3 года назад +45

    Man, I don't even know if you ever read this, but your channel is like an amazing one. Perfect tutorials with relaxing atmoshere. thousand thanks!

    • @WebDevSimplified
      @WebDevSimplified  3 года назад +14

      Thank you so much. That means a lot to me.

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

      I agree. I feel like this is the gold standard for coding tutorials. Good pacing, no nonsense, huge help for me.

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

    The first 1000 people to use the link will get a free trial of Skillshare Premium Membership: skl.sh/webdevsimplified11201

  • @vishalcelestine8654
    @vishalcelestine8654 3 года назад +18

    Started with your video on node +mongo+express blog tutorial yesterday. Loved the way you keep things concise ,clear and especially your calm voice. Subscribed :)

  • @ferhatgiritli8569
    @ferhatgiritli8569 2 года назад +5

    suits are also alt numpad (3,4,5,6) in the order of ♥♦♣♠
    to write them hold down alt, type the 1 or more digit number from numoad, release alt

  • @azsamsiizbrah
    @azsamsiizbrah 3 года назад +18

    This game is currently endless since the draw simply returns the cards to their owner's decks. With this rule no one can take an opponent Ace card. There was a rule for the draw situation- when it occurs, both players flip 3 additional cards and compare the last flipped. This way you could take the opponents Ace cards and win.

    • @Gaff.
      @Gaff. 2 года назад +1

      Never coded in js before, but I've done a lot of scripting in GECK for Fallout mods, and at least for me, I found it to be a really informative introduction to js to follow this video and then solve the problem you've mentioned. I have just a couple of aesthetic things to take care of and I need to do something about when the war itself is a draw.

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

      Another, probably easier method would be, to just remove both cards from the game on a draw.

    • @Gaff.
      @Gaff. 2 года назад

      @@jabbadar I had that implemented inadvertently on my way to implementing the part that''s missing (the 'War' part), and it leads to endless games as well.

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

    A little nostalgic tutorial. It's a game of my childhood :) Ty Kyle

  • @billyzman666
    @billyzman666 3 года назад +4

    Its impressive how easily you get around and create your code, thank you for this video!

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

    Great video, note a player with any Ace in the deck can never lose :P

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

      Because "2" should beat "Ace"...i just added two if statements before the rest of them: if (isRoundWinner(computerCard, playerCard) && playerCard.value == 2 && computerCard.value == 'A') to be win and swap "player" and "computer" in the second one to be lose

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

      Therefore it never ends XD

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

    Love watching your videos!
    Note: your shuffle function will never have the last card remain in the last slot.

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

      He could've articulated the algorithm a bit more clearly but the code is fine. The random index "before" the current card includes the current card so it can "swap" with itself.

  • @avi12
    @avi12 3 года назад +5

    When I need to use "document.querySelector()", I use a variable that begins with "el", to signify an element
    Also, for booleans, I use a variable that begins with "is", even if the boolean signifies a plural

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

      Why not to use "are" instead of "is" for plural variables? :-)

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

      @@ladislavzima8382 To be consistent, so when briefly reading the code, whenever you encounter a variable prefixed with "is", you know to expect it to contain a boolean

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

      I do the same thing. And I frequently find myself wondering why I don't just learn typescript.

  • @javascriptdev2273
    @javascriptdev2273 3 года назад +3

    you always add something unique to your videos

  • @bunnybloods768
    @bunnybloods768 3 года назад +3

    Diwali is a festival of lights. By watching your videos one day my life will be bright.❤️❤️❤️❤️

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

    how do add a picture after the even of winning or losing happens?

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

    PDF annotation tools are mostly paid. JS tutorial explaining basics of PDF annotation layer / editing pdf would be very helpful.

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

    Awesome tutorial!
    I'm playing already a 23 hours match and can't beat that computer beast... but I never give up!
    If the computer and the player have at least one Ace... the game will take forever...
    Try with...
    const SUITS = ["♣","♦","♥","♠"]
    const VALUES = ["A"]
    ...but as the tutorial is not about Gameplay ;-) Structuring of classes with getHTML() and injecting the elements into the DOM depended on the game state, helped me understanding how very simple VanillaJS game could be structured. Thanks for sharing! Love it!

  • @themaninblack5022
    @themaninblack5022 3 года назад +3

    BEWARE there are loud clipping sounds that will RIP your ears. 8:53 12:30 possibly more. RIP RIP RIP but damn this is great content

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

    keep up the superb work, I've learnt so much from this tutorial(as well), thank you Kyle

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

    9:45 I don’t quite get why using random with the sort function causes the shuffle to not be totally random. Can anyone help explain? :)

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

    Never seen defer before! Must follow this and make a Texas Holdem game, so is flatMap a spread under the hood, thanks Kyle!

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

    Your videos are great...succinct and informative.

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

    Amazing and simple to understand as always. Thanks for the content.

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

    Love your tutorials. I think I bit off more than I could chew because I chose to code Solitaire as my first coding project for bootcamp. This will help me out a lot because all I'm trying to do now is get some dang cards on the screen 😂.

    • @boblebeau1363
      @boblebeau1363 6 месяцев назад

      Boss man im coding solitaire and im lost

  • @gerson-v-w5b
    @gerson-v-w5b Год назад

    I didn't quite understood how the const newIndex works. I got lost in the (math.random() * (i + 1)). Im not sure hoe the * works in this case. What are you multiplying? And why are you adding 1? You explained that this would essentially swap our current card with a random card that we havent looped through yet but Im just confused as to why we use multiplication and addition to achive this.

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

    I have a question. The only way I can get modules to work is to have a server on through node. Do you just always have the server on in your videos?

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

    if playerDeck and computerDeck are an object made from the class Deck then how is it able to access the getHTML property from class Card?

  • @piyushmahapatra5402
    @piyushmahapatra5402 3 года назад +10

    Happy Diwali Bhai ❤️

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

    Is that fisher-yates shuffle algorithm at 11.45

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

    Github Copilot knows a bunch of this code already

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

    Hey Kyle love the video just wanted to ask you if the design pattern you implemented in this video was factory right ? Dope content non the less! The design pattern videos have helped me beyond belief

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

    Awesome video. Can you please write test cases for this project. It will be very helpful.

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

    Thanks for such an amazing tutorial. If you publish a product rating system using with node or mongoose that would helpful.

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

    Thank amigo. Question about game logic. If ties always go back to the bottom of each player's deck, then any play with an ace can never lose, because every round will be either a win or a tie for that card.

    • @Gaff.
      @Gaff. 2 года назад

      A 'war' should occur at that point, with each player putting up additional cards (usually 3 I think), and the winner of the last comparison takes all those cards. In this way, aces can be taken as part of the pile. I added this to my file and found it a helpful problem to work through.

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

    cool thanks for showing a use for the get statements in classes! funny that numberOfCards is actually 1 character longer than cards.length tho

  • @LokeshKumar-vo2xc
    @LokeshKumar-vo2xc 3 года назад +1

    Happy Diwali bhai

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

    Great tutorial Kyle!

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

    Dude you are a legend

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

    When I download the Skillshare iOS app, it offers a month-long trial which is longer than your two-week trial code, are you getting stiffed by Skillshare?

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

    Please make a video on creating a full featured code editor using javascript.

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

    Thanks for your videos, you are the best

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

    amazing tutorial
    thnx a lot Kyle

  • @ransom.52
    @ransom.52 2 года назад

    ...if there was a war between... 2-4 players maybe 4 additional in lobby, how would you code that deal?...

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

    Instead of doing Math.floor() I always do,
    5.76 | 0
    Which return the number 5.
    Is it good to do that?

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

      This guy has a good video explaining what | is and what it's can be used for. Personally I would use Math .floor & .celi for rounding.
      ruclips.net/video/mesu75PTDC8/видео.html

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

    Wonderful tutorial, thx a lot =)

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

    How would you deal with the logic of a blackjack card game? Especially with the Ace card where it can be 1 or 11 depending on what the player has before

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

      If totalValue > 21 { check to see if there are aces, if so reduce value of ace to 1 and check again, if not then go to BUST} something like that

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

    Thank you for this contet!

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

    Happy diwali

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

    I'm having trouble at ruclips.net/video/NxRwIZWjLtE/видео.html (32:51) after taking out the hard coded 26 I end up with no numbers in the deckElements.
    I looked at my code and it seems to be the same even copy and pasted the code from the github to triple check typing errors.
    The error that I'm getting is "Uncaught TypeError: Cannot set properties of null (setting 'innerHTML')" for the cleanBeforeRound().
    any ideas?

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

    Very well made. Awesome

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

    I feel stupid asking this but...how do I run this program? I did the entire tutorial, but don't know how to actually run the program. Do I need to find the server/host and run it from the terminal?

    • @stianmartinsen-stormyr1737
      @stianmartinsen-stormyr1737 3 года назад

      If you use Visual Studio Code you can install the "Live Server" Extension...when it`s installed you simply click the "Go Live"-button and it will open a browser window with your current code and it updates automatically while you code.

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

    If that is all in client side it means all card values can be manipulated?

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

    Great info, thank you.

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

    This is epic pog.

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

    I like your Javascript lessons, on this one I keep getting error in console:
    Uncaught TypeError: Failed to resolve module specifier "color-name". Relative references must start with either "/", "./", or "../".
    the code is word for word from your GitHub..

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

    is using flatMap the same as mapping the spread of ...suit @ 8:45?

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

    Hi Kyle, what programming paradigm do you mostly use?

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

    hi when i write console.log(deck.cards) i get this message Cross Origin Request Blocked error is comming what i must do to look the array of cards

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

      how are you opening the index.html file?

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

      @@barrydlight17 hi i open the index with chrome

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

      @@tomimontaana50 Try using a local server, if you check Kyle bar direction shows localhost, a simple way of doing it is to install live-server with npm and running it on the folder you're developing in.

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

      @@barrydlight17 thanks in live server is running

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

      @UCRxvbXNAyPLJ-6UU6jRMpUw you need node.js installed on your machine, after that, run "npm i -g live-server" this will install live-server as a global dependency, once is finished just open your project folder in a terminal and run "live-server", it will look for an index.html file to serve it or you can run "live-server file.html" to specify the exact file you want to serve.

  • @liLi-lg8xv
    @liLi-lg8xv 2 года назад

    Your hair looks awesome 👌

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

    Hi Kyle why dont you use factory function instead of class?

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

    Does anyone know how to make the array return 5 cards? Please

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

    You are the best! 👌🏻

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

    Good job man

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

    Do you offer a discounted bundle for the JavaScript and React course?

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

    Thank you

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

    How make it multiplayer?

    • @Gaff.
      @Gaff. 2 года назад +1

      Wouldn't you just change the strings to reflect Player 1 and Player 2? War isn't really a 'game' in that neither player has any agency and the outcome is predetermined once the decks are given to each player.

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

    Ты крут, чувак!

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

    !(I understood all your code)

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

    awesome, bro

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

    Nice video sir, I want one video on voice recognition using google API for react native App. Please help me.

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

    @8:53 thought i was having a stroke

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

    hi master !
    Can you build a simple flashcard app ?

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

    How did you make that horizontal array (value and suit) vertical?

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

      i also wonder this let me know if u found it

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

      @@MikeAgge He is using an extension called prettier, when he presses ctrl+s or ctrl+shift+i it formats automatically.

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

    if i get the money im going to register in skillshare :)

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

    suit, rank*

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

    Bravo!

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

    Happy Diwali

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

    Beautiful

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

    Hey what about a chess clone?

  • @Roknok
    @Roknok 3 года назад +4

    Happy children's day!

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

    Great!!!

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

    I would love for your help to develop an app! This is amazing!

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

    Build a Poker Game pls (Hold' em Texas) lol

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

    13:50 No Pattern completely random, ME sees J, J, J, 10,10,10

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

    Hi is your react course [Learn React Today] up to date?

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

      It is. It uses hooks and function components for everything.

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

    So bummed I cannot afford your JS course.

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

    Cross Origin Request Blocked error is comming

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

      What would be your suggestion for an easy clean solve?

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

    Unless all aces are served to one player, isn't it an endless game ?

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

    There is a bug here: Once player has an Ace in his deck , he will never lose.

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

      Why?

    • @stianmartinsen-stormyr1737
      @stianmartinsen-stormyr1737 3 года назад

      Yeah, I`m thinking the same.

    • @stianmartinsen-stormyr1737
      @stianmartinsen-stormyr1737 3 года назад

      @@twinkiefrost6668 Because each ace got the value of 14, and when there is a draw both cards is put back in the same players deck, so there is no way to lose an ace.

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

      @@stianmartinsen-stormyr1737 that's because the "war" part of the game wasn't implemented or even mentioned. but maybe that could be a fun challenge for viewers to implement.
      i'd also say splitting the deck in half is not a proper deal, but it probably doesn't matter since the cards have been pseudo-randomly shuffled. it's trivial to implement a deal for odd/even cards out of the original deck into the computer/player decks instead of splitting on the midpoint.
      but all of that is irrelevant to the point of the video, which is how to set up a deck and cards to make whatever game you want.

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

    Min 5:56 😅

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

    I need you help sir

  • @avi12
    @avi12 3 года назад +4

    8:53 What the hell is that sound?

    • @WebDevSimplified
      @WebDevSimplified  3 года назад +3

      Lol. I have no idea. Sounds like my computer was yelling at me

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

      @@WebDevSimplified happy diwali

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

    I cant even figure out how spread out cards on the x axis 😭

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

    can you share your pc config??

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

      Lol why

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

      @@abe10 because I want to build a new one... Just to get an idea

  • @user-ri9cn2rs5i
    @user-ri9cn2rs5i 2 года назад

    watched the tutorial basically twice and made sure all the characters were correct and the game is still not rendering correctly...

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

    Whaaattt, the script is vanilla JS right? Why there's no *";"* to terminate a statement? Is it considered best practices nowadays to not explicitly do that, or am I missing something? Is it the new standard?

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

      Works with and without. I choose to use a ';' because i also program in C,C# where you have to use it. Simplifies live for me. :)

  • @ArvindKumar-sm6uh
    @ArvindKumar-sm6uh 2 года назад

    Rxce app mod bana do

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

    Please explain in java

  • @AP-ds9bb
    @AP-ds9bb 2 года назад

    how do I contact you?

  • @digital-artefakt
    @digital-artefakt 2 года назад

    i have made a blackjack with python and it is way easier than this:D

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

    i dont understand a word. i just this video is only for english speakers. Try to speak slowly and explain every function or built in function.. Thnks

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

    broo just tell us what we need to put in fucking first instead of going back n changing shit