-
-
Save photofroggy/3808737 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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