Step4: Adding the Card Class (called from Deal function)
//Hand Constructor
var Hand = function(){
this.card1 = deal();
console.log(“card1 is “+this.card1.number+” of “ + this.card1.suit);
this.card2 = deal();
console.log(“card2 is “+this.card2.number+” of “ + this.card2.suit);
};
//Card Constructor
function Card(s,n){
this.number = n;
this.suit = s;
getSuit (method to interpret suit numbers)
getValue(method to interpret value unbers)
}
//Deal function
var deal = function(){
var suit = Math.floor(Math.random()*4)+1;
console.log(“deal function suit: “+suit);
var number = Math.floor(Math.random()*13)+1;
console.log(“deal function number: “+number);
return new Card(suit,number);
};
//Main Function
var myHand = new Hand();
New text is highlighted in red(Although I’m not sure this formatting will follow through to the post). Here we are adding a function call at the end of the ‘deal’ function in the form of a ‘return’ statement. This means that the deal function will generate two random numbers for us and then send these to the ‘card’ constructor to make our new card objects.
I’m leaving most of the card object unfinished at this point. We will come back later to add methods for interpreting the information associated with each card object.