Day 10: Moar Cards / Chat Bot
Introduction
Today we will practise JavaScript Objects. Choose one of the two exercises, Moar Cards or Chat Bot, and work your way through up till your preferred level of comfort. You are free to complete the other exercise at your own time.
Base
Feel free to copy the card deck generation function from 9.2: Card Deck Generation and the card shuffling functions from 9.1: JavaScript Objects into your script.js
file.
Display Single Card
Build an app using the Fundamentals Starter Code and the pre-class deck functions such that when the user clicks Submit, draw a single card from a shuffled deck and show it to them.
Low Card
Implement the High Card game from 9.1: Objects with 1 difference: the winner is the person with the lowest card.
Low Card with Queen Winner
Alter the Low Card game such that if any player draws a Queen, they win.
Low Card Hands
The player can input how many cards they want. The lowest of the player's cards is compared against the computer's 1 card. Show the player all the cards that they drew. Rules from above exercises continue to apply.
Low Card Suit Output
Implement a nice-looking output for Low Card. Use a helper function to display each card nicely with emoji (β οΈ, β₯οΈ, etc.). Try to avoid repeating code if possible.
Example:
Player 1 drew:
1 of β¦οΈ.
Player 2 drew:
6 of β£οΈ.
6 of β£οΈ beats 1 of β¦!
Player 2 wins!
More Comfortable
Low Card with Wild Card
Update our latest Low Card implementation with the following twist. At the beginning of the game, pick (but do not draw) a random card in the deck to be the Wild Card. If either player draws the Wild Card, that player automatically wins.
Low Card with Player-Chosen Wild Card
Same rules as Low Card with Wild Card, except at the beginning of the game the player names a single card as input to be the Wild Card. The Wild Card can be identified with a card name and suit.
Low Card with Bets
Allow the player to wager points on each round. Add a new mode for the beginning of each round where the player selects the number of points to wager. They win the wagered points if they win, and lose the points if they lose or draw. The player begins with 100 points. After each round, output the player's remaining points.
Low Card 2-Player Mode
2 human players play against each other. The computer draws 3 cards for each player at the start of the game. The players take turns playing 1 card from their hand at a time. For each card played per player, the lowest card wins. The player that wins the best of 3 wins overall. The grey box will tell the players to switch so they don't see each other's cards.
Low Card 2-Player Mode with Pairs
Update the previous game logic such that if any player gets a pair in their hand, they win.
Reference Solutions
Here is a reference solution for Day 9 exercises. Please only view the reference solution for each exercise after you have attempted the exercise yourself. Note that there are many ways to implement these solutions and the reference solution is only 1 way.
Last updated