Skip to content

Instantly share code, notes, and snippets.

@photofroggy
Forked from anonymous/gist:3808735
Created September 30, 2012 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save photofroggy/3808737 to your computer and use it in GitHub Desktop.
Save photofroggy/3808737 to your computer and use it in GitHub Desktop.
// Make your card constructor again here, but make sure to use private
// variables!
function Card(s, n) {
var suit = s;
var number = n;
this.getSuit = function() {
return suit;
};
this.getNumber = function() {
return number;
};
this.getValue = function() {
if(number > 11 && number < 13) {
return 10;
} else if(number === 1) {
return 11;
} else {
return number;
}
};
}
// Make a deal function here. It should return a new card with a suit
// that is a random number from 1 to 4, and a number that is a random
// number between 1 and 13
var deal = function() {
return new Card(
Math.floor(Math.random() * 4 + 1),
Math.floor(Math.random() * 13 + 1)
);
};
// examples of the deal function in action
var card1 = deal();
var card2 = deal();
console.log(card1.getSuit);
console.log(card1.getNumber);
console.log(card1.getValue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment