Search code examples
javascripthtmlreferenceerror

ReferenceError when calling external JS function


Just messing around with incremental games and I can't seem to get my onclick() to work properly.
HTML

<html>
<head>
<link rel="stylesheet" type="text/css" href="interface.css" />
<script type="text/JavaScript" scr="main.js"></script>
</head>
<body>
<button onclick="goldClick(1)">Click Me!</button>
<br />
Gold: <span id="gold">0</span>
<br />
<button onclick="buyMiner()">Buy Miner</button>
<br />
Miners: <span id="miners">0</span>
<br />
Miner Cost: <span id="minerCost">15</span>

</body>
</html>  

JS

var gold = 0;

function goldClick(number) {
      gold += number;
      document.getElementById("gold").innerHTML = gold;
};

var miners = 0;

function buyMiner() {
      var minerCost = Math.floor(15 * Math.pow(1.1,miners));
      if(gold >= minerCost){
                miners = miners + 1;
                gold -= minerCost;
                document.getElementById('miners').innerHTML = miners;
                document.getElementById('gold').innerHTML = gold;
      };

      var nextCost = Math.floor(15 * Math.pow(1.1,miners));
      document.getElementById('minerCost').innerHTML = nextCost;
 };

window.setInterval(function(){
      goldClick(miners);
}, 1000);

If I click on either of the buttons, I get "goldClick/buyMiner is not defined" as if my JS has an error or isn't being called properly. the JS is in the same directory as the html so I don't believe it is the pathing.


Solution

  • If that's a direct copy of the html, it looks to be a simple typo:

    <script type="text/JavaScript" scr="main.js"></script>
    

    You've got scr instead of src