I am totally new to javascript, but I can program in Java, C# etc. already.
I want to generate a card deck, and after that I want to access this array of cards.
function Card(rank, suit)
{
this.rank = rank;
this.suit = suit;
}
function Deck()
{
this.ranks = new Array("A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K");
this.suits = new Array("Hearts", "Clubs", "Diamonds", "Spades");
this.cards = Array(52);
this.makeDeck = function()
{
console.log("Executed MakeDeck!");
for(var i = 0; i < this.suits.length; i++)
{
for(var j = 0; j < this.ranks.length; j++)
{
this.cards.push(new Card(this.ranks[j],this.suits[i]));
}
}
}
}
function btnClick()
{
var deck = new Deck();
deck.makeDeck();
console.log(deck.cards[0]);
}
In the function "btnClick()" I want to log the first item in the array, but the console just tells my "undefined". I can't find my mistake, maybe you can help me?
new Array()! Use array literals:["A","2",...];