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

Wednesday, December 5, 2012

Codecademy: Codeyear Deal them out


//sample solution


// Make your card constructor again here, but make sure to use private
// variables!
function Card(suit, number){
 var suit = suit;
 var number = number;
 //methods
 this.getSuit = function(){
  return suit;
 };
 this.getNumber = function(){
  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(){
var randomSuit = Math.floor(Math.random()*4+1);
var randomNumber = Math.floor(Math.random()*13+1);
var randomCard = new Card(randomSuit, randomNumber);
return randomCard;
}

// examples of the deal function in action
var card1 = deal();
var card2 = deal();

//test
console.log(card1.getSuit());
console.log(card1.getNumber());
console.log(card2.getSuit());
console.log(card2.getNumber());

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts