-6
<!DOCTYPE html>
<html>
<body>
<h1> Slap Jack </h1>
<p id="message"> </p>
<button type="button" onclick="investMoney()"> How much money are you betting? </button>
<script type="text/javascript">
var gambledMoney;
var money;
var investMoney = function() {
gambledMoney = prompt("How much?");
document.getElementById("message").innerHTML = gambledMoney;
};
var totalAmount;
var card;
var pullCard = function() {
card = Math.floor(Math.random() * 14 + 1);
totalAmount = +card;
document.getElementById("test").innerHTML = card + " " +
"Do you want to pull again?";
document.getElementById("p").innerHTML = "Total points" + " "
totalAmount;
};
</script>
<p id="test"> </p>
<p id="p"> </p>
<button type="button" onClick="pullCard()"> click me to pull a card </button>
</body>
</html>
卡是隨機的,當你定義卡時它會顯示卡。我也想要顯示多少點的總數。當我嘗試運行代碼時,沒有任何反應。你能幫我調試這個黑色插孔遊戲嗎?
你的代碼中有一個語法錯誤:''Total points「+」「totalAmount;' - 缺少'+'符號。 – aaronk6 2015-03-02 20:27:02
您應該在您使用的瀏覽器中使用開發者控制檯。它通常會告訴你代碼中的錯誤。 – 2015-03-02 20:30:39
我建議通過[JSLint](http://jshint.com/)運行您的JavaScript代碼以查找錯誤。 – 2015-03-02 21:01:10