Quotes help make search much faster. Example: "Practice Makes Perfect"

Monday, December 10, 2012

Codeyear: Rethinking Hands


//sample solution


// Card Constructor
function Card(num1,num2) {

//properties
var suit = num1;
var number = num2;

//methods
this.getNumber = function(){
return number;
};
this.getSuit = function(){
return suit;
};
this.getValue = function(){
if(this.getNumber()>=10){
return 10;
} else if(this.getNumber() === 1){
return 11;
} else {
return number;
}
};
}

function deal(){
var newSuit = Math.floor(Math.random()*4+1);
var newNumber = Math.floor(Math.random()*13+1);
var newCard = new Card(newSuit,newNumber);
return newCard;
}

function Hand(){
//properties
var newCard1 = deal();
var newCard2 = deal();
var handArray = [newCard1, newCard2];
//method
this.getHand = function(){
return handArray;
};
}

var newHand = new Hand();
var tempArrayOfCards = newHand.getHand();
console.log(tempArrayOfCards[0].getSuit());
console.log(tempArrayOfCards[0].getNumber());
console.log(tempArrayOfCards[0].getValue());
console.log(tempArrayOfCards[1].getSuit());
console.log(tempArrayOfCards[1].getNumber());
console.log(tempArrayOfCards[1].getValue());

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts