买不闲着的游戏

时间:2015-09-27 10:29:21

标签: javascript html dom

我正在进行闲置/点击游戏,当我尝试购买手臂时,它根本不做任何事情。我几乎尝试了所有我知道的东西,但我无法通过互联网获得任何结果。

HTML:

<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <link rel="stylesheet" type="text/css" href="css/interface.css" />
        <title>Jujhar Clicker</title>
    </head>
    <body>
        <script type="text/javascript" src="js/main.js"></script>
        <div style="position: absolute; top: 30px; right: 660px;"><button id="Face" onClick="faceClick(1)" style="position: static" align="center"><img src="images/face.png"><p align="center" style="line-height:-200em">Click Me!</p></button></div>
        <div style="position: absolute; top: 10px; right: 690px;"><a>Faces: </a><span id="faces" style="right:20px">0</span></div>
        <button id="RoboticArm" onClick="buyArm" style="position: static" align="center"><img src="images/ArmStore.png" /></button>
        <div style="position: absolute; left: 20px;"><span id="arms">Amount: 0</span>
        <a>Cost: </a>
        <span id="armCost">10</span></div>
    </body>
</html>

使用Javascript:

var faces = 0;
var arms = 0;

function faceClick(number) {
    faces = faces + number;
    document.getElementById("faces").innerHTML = faces;
};

function buyArm() {
    var armCost = Math.floor(10 * Math.pow(1.1,arms));
    if (faces >= armCost) {
        arms = arms + 1;
        faces = faces - armCost;
        document.getElementById('arms').innerHTML = "Amount: " + arms;
        document.getElementById('faces').innerHTML = faces;
    };
    var nextCost = Math.floor(10 * Math.pw(1.1,arms));
    document.getElementById('armCost').innerHTML = nextCost;
};

1 个答案:

答案 0 :(得分:0)

好像你只有一个小错误。您没有正确调用buyArm()函数,因为您忘记添加括号。

onClick="buyArm"更改为onClick="buyArm()"

Demo

测试这类错误的好方法是在Chrome中打开它,右键单击&gt; &#34;检查元素&#34;并阅读Developer Tool屏幕底部的任何错误。