Hey again!
So at this point you might be asking yourself, did he manage to keep it under 5 minutes?
Well..no
Ok but did I stick to the actual project outline?
Well...also no....
But LOOK I decided to challenge myself again this week and started digging into HTML and CSS...a little early....
This week I decided to make an interactive war game, not an automated one, and I use the built in JS dom methods to update the player cards so they are displayed on the screen along with the user score!
Here's a quick code snippet of how I did that within the player class:
This function uses a reference to the player's card in the DOM to then loop through a DOM node list (you get that returned in querySelectorAll) and update the html of each element as well as the color of the text based on the specific card.
The card color is actually determined with this beauty:
That is a getter method that basically runs a comparison on the card's suit and returns the color of the specific suit (which are just html entities for the symbols on the cards you can look them up)!
AND
Which does the same thing just way more simple by updating the html counter with the score of the player!
I did all of this in the interactive game by running the War games runRound method on a click event fired on a button!
That looks like this:
dealButton is actually another dom reference using querySelector() that I do higher in that file and game is just an instance of my WAR class!
The run round gets fired on every click and basically checks to see if either player is out of cards. If they are then it ends the game by announcing the winner, and if they aren't then it runs through a comparison of the values of each player's card (that they draw) then updates the player score accordingly! (I do have a bug with ties that I need to address though)
Oh also I used the mocha and chai testing js library to run some tests but I'm not sure how I feel about them. I also MAY have done so using JS modules instead of just a singular JS file sooooo yeah there's that.
Anyways, the project details are as follows:
Whelp that's it!
Until next time, onwards and upwards!
-Travis