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

Monday, December 10, 2012

Codeyear: Show Me What You Got


//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];
//methods
this.getHand = function(){
return handArray;
};
this.printHand = function(){
suitsArray = ["clubs","diamonds","hearts","spades"];
numberArray = ["ace",2,3,4,5,6,7,8,9,10,"jack","queen","king"];
return numberArray[newCard1.getNumber()-1]+" of "+suitsArray[newCard1.getSuit()-1]+", "+numberArray[newCard2.getNumber()-1]+" of "+suitsArray[newCard2.getSuit()-1];
};
this.score = function(){
scoresum = 0;
for(var i=0; i<handArray.length; i++){
scoresum += handArray[i].getValue();
}
return scoresum;
};
}

var newHand = new Hand();
var tempArrayOfCards = newHand.getHand();
console.log(newHand.printHand());
console.log("The score of the hand is "+newHand.score()+".");

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts