"use strict"; myMain(); function myMain() { var ncards=52; var deck = makeDeckObj(ncards); deck.show(); deck.shuffle(1000); deck.show(); var h = deck.deal(5); h.show(); deck.show(); h.shuffle(25); h.show(); } function makeCard (cn) { var suits=["D","C","H","S"]; var faces=["2","3","4","5","6","7","8","9","X","J","Q","K","A"]; var card={ num: cn, face: faces[cn%13], suit: suits[Math.floor(cn/13)], show: function() {alert(this.num+":"+this.getName());}, getName: function() {return this.face+this.suit;}, }; return card; } function makeDeckObj(nCards) { var deck= { cards: [], numCards: nCards, shuffle: function(times) { var slot1, slot2, temp; for(var i=1; i<=times; i=i+1) { slot1 = genRandomInt(0, this.numCards-1); slot2 = genRandomInt(0, this.numCards-1); temp = this.cards[slot1]; this.cards[slot1]=this.cards[slot2]; this.cards[slot2]=temp; } }, addCard: function(card) { this.cards[this.numCards] = card; this.numCards++; }, deal:function(num) { var hand = makeDeckObj(0); for (var c=0; c=1 && n<=this.numCards) { return this.cards[n-1]; } return null; }, size: function() { return this.numCards; }, }; deck.init(); return(deck); } function genRandomInt(min,max) { return Math.floor(Math.random()*((max-min)+1))+min; }