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 document.write (JSON.stringify ()); is the content using below. The 'main' method in the lower part is trying to call me cardtostring, which should take the contents of the object, and then return a string that is output. I can not figure out what I'm missing.

  (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    

To get the value from the card object, you have to pass it cardToString () as argument. Since the name of your object is card it is cardToString (Card) . Will be written as.

Change the 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

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -