我正在尝试通过 javascript 创建一个通用的二十一点游戏。点击开始按钮后游戏开始:
<button type="button" onClick="deal()">Start Game</button>
依次运行方法 deal:
function deal() {
card1 = Math.floor(Math.random() * 52);
card2 = Math.floor(Math.random() * 52);
card1 = changeCard(card1);
card2 = changeCard(card2);
score = card1 + card2;
for (var i = 0; i < aceAmount || score > 21;aceAmount--) {
score -= 10;
}
document.write("You were dealt a " + card1 + " and a " + card2 + " for a total of " + score + ".\nDo you wish to hit or pass?");
aceAmount = 0;
};
我的问题是一旦 deal 方法运行,我怎样才能让两个 html 按钮显示在屏幕上,例如:
<button type="button" onClick="hit()">Hit</button>
<button type="button" onClick="pass()">Pass</button>