I'm trying to make a simple "click this and make a number go up" button, but I get the error:
Uncaught TypeError: Unable to set property "innerHTML" in null
I've tried changing the order of some of the code, but it didn't work.
JS code:
var testCurrency = 0;
function addNumber(number){
testCurrency += number;
}
document.getElementById("testCurrency").innerHTML = testCurrency;
HTML code:
<!DOCTYPE html>
<html>
<head>
<title>Yet Another Idle Game</title>
<link rel="stylesheet" type="text/css" href="interface.css" />
</head>
<body>
<button onclick="addNumber(1)">
<script type="text/javascript" src="main.js"></script>
</body>
Error:
Uncaught TypeError: Cannot set property 'innerHTML' of null
at addNumber (main.js:6)
I don't know how to make it work. The error appears as soon as I open the page. Can anyone help me? Thanks in advance!