二十一点游戏:我做了下面的发牌函数,它应该返回一个代表花色的 1-4 之间的随机数,以及另一个代表卡号的 1-3 之间的随机数。
当我通过调用它来测试代码时,console.log(getSuit(card1));
它返回 NaN
有谁知道为什么?
// Make your card constructor again here, but make sure to use private
// variables!
function Card(num, suit){
var num = num;
var suit = suit;
getSuit = function(){
return suit;
};
getNumber = function(){
return num;
};
getValue = function(card){
if (card > 10){
return 10;
}else if (card === 1){
return 11;
}else{
return card;
}
};
}
// 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 suit = Math.floor(Math.random * 4 + 1);
var number = Math.floor(Math.random * 13 + 1);
return new Card(number, suit);
};
// examples of the deal function in action
var card1 = deal();
var card2 = deal();
console.log(getSuit(card1));