【问题标题】:Can you help me debug this black-jack game?你能帮我调试一下这个二十一点游戏吗?
【发布时间】:2015-05-03 08:07:21
【问题描述】:
<!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; – 缺少+ 符号。
  • 您应该在您正在使用的浏览器中使用开发者控制台。它通常会告诉您代码中的错误。
  • 我建议您通过JSLint 运行您的javascript 代码以查找错误。

标签: javascript html


【解决方案1】:

第 22 行出现错误
缺少字符串连接符号 [+]。

【讨论】:

    猜你喜欢
    • 2022-01-19
    • 2023-03-21
    • 2020-05-18
    • 1970-01-01
    • 2016-01-08
    • 2014-10-22
    • 2022-11-12
    • 2012-10-16
    • 2015-06-02
    相关资源
    最近更新 更多