As of now, I am making a simple no internet dinosaur game that everyone is familiar with using HTML, JS and CSS. I have been working my way through it and I have gotten everything working for the past few hours. All of a sudden, my buttons weren't working giving me the error: Uncaught ReferenceError: start is not defined at HTMLButtonElement.onclick
I tried changing the functions of the buttons and the IDs but none of it worked. My conclusion is that my script.js file isn't loading with the HTML file for whatever reason but the .css file is. The following code is the HTML.
<div id="game">
<div id="character"></div>
<div id="block"></div>
</div>
<div>
<button class="btn btn-secondary" id="button" onclick="start()">Start</button>
<button class="btn btn-secondary" id="button2" onclick="pause()">Pause</button>
</div>
</body>
<p id="paused"></p>
<p id="score"></p>
<script src="script.js"></script>
</html>
The code below is the code for either function.
function start() {
document.getElementById("button").innerHTML = 'Jump'
button.setAttribute( "onclick", "jump()")
block.classList.add("movement")
}
function pause() {
pauseStatus = true
}
I don't know what the problem might be. I haven't made any changes to the file paths or anything and I can't think of how to fix the problem. I've tried putting the src path both in the body and outside of the body in the HTML and it hasn't worked.
` are invalid. Where is `jump` defined? If this is not the full `script.js`, then make sure you provide a [mre]. Possible cause: [Function is not defined - uncaught referenceerror](https://stackoverflow.com/q/5067887/4642212).
– Sebastian Simon Mar 17 '21 at 07:07