Im learning some javascript and have hit a stumbling block.. I would like to select 2 random values from my array and save them into a variable (which will be another array i guess) called Deal, i can get one random value but not 2.. My code is as follows
var deckOfCards = []; //declaring an empty array to put Cards into later
function Card(name, value, altValue) { //function that defines a card object ( key part is "this")
this.cardName = name;
this.cardValue = value;
this.cardAltValue = altValue || false;
}
var suits = ['Hearts', 'Diamonds', 'Spades', 'Clubs'];
var values = ['Ace', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Jack', 'Queen', 'King'];
for(var i in suits) //loops through each of the suits
{
for(var j in values) { // loops through each of the cards for the suit
if(values[j] != 'Ace') {//j is the index within the array,
var cardValue = parseInt(j, 10) + 1;
if(cardValue > 10) cardValue = 10;
deckOfCards.push(new Card(values[j] +' of ' +suits[i], cardValue));//adding a new card object to deckOfCards
} else {
deckOfCards.push(new Card(values[j] +' of ' +suits[i], 1, 11));// adding alternate value to deckOfCards
}
}
}
var Deal = deckOfCards[Math.floor(Math.random()*deckOfCards.length)];;
console.log(Deal);
Could anyone give me a pointer on this please
Thanks