javascript - Printing out Deck of Cards -
I try to figure out what I'm missing! Make a card, I can print the object and it's To get the value from the card object, you have to pass it Change the
(function () {function card (rank, suit) {this.rank = rank; this.suit = suit;}; function deck () {this.deck = new Array () ; this.makeDeck = makeDeck; this.shuffle = shuffle; this.deal = deal;} function medec () {var rank = new array ("A", "2" 3 "," 4 "," 5 "," Var suits = new arrays ("c", "d", "h", "6", "7", "8", "9", "10", "J", "Q", "K" "S"); this.deck = new array (52); var i, j; for (i = 0; i
cardToString () as argument. Since the name of your object is
card it is
cardToString (Card) . Will be written as.
cardToString function slightly to draw the value from the card object. Instead of using
this , you will use the name that you designated the code as
card I have updated the function below and how you can work it The idea has been given.
function cardstorestring (card) {var rank, suit; Switch (card.rank) {case "A": Rank = "Ace"; break; Case "2": rank = "two"; break; Case "3": rank = "three"; break; Case "4": Rank = "Four"; break; Case "5": Rank = "Five"; break; Case "6": Rank = "Six"; break; Case "7": rank = "seven"; break; Case "8": Rank = "Eight"; break; Case "9": rank = "nine"; break; Case "10": Rank = "Ten"; break; Case "J": Rank = "Jack"; break; Case "Q": Rank = "Queen"; break; Case "of": rank = "king"; break; Default: rank = null; break; } Switch (card. Suit) {case "c": suit = "club"; break; Case "D": suit = "diamond"; break; Case "H": Suite = "Heart"; break; Case "s": suit = "spades"; break; Default: Suite = Null; break; } If (rank == empty || suit == faucet) {return ""; } Return rank + "of" + suit; }
Comments
Post a Comment