Why are my javascript functions not responding

I linked js in HTML at the bottom of my page all the other code in my js file works perfectly except the functions.


function ClickMoreGold() {
    let coin = document.getElementById("coin-count").innerHTML;
    document.getElementById("coin-count").innerHTML = coin;

function countTimer() {
    let hour = Math.floor(totalSeconds / 3600);
    let minute = Math.floor((totalSeconds - hour * 3600) / 60);
    let seconds = totalSeconds - (hour * 3600 + minute * 60);
    if(hour < 10) {
        hour = "0" + hour;
    if(minute < 10) {
        minute = "0" + minute;
    if(seconds < 10) {
        seconds = "0" + seconds;
        document.getElementById("timer").innerHTML = hour + ":" + minute + ":" + seconds;


Online time <span id="timer" title="Time"></span> &nbsp;&nbsp;
<span style="background-color: rgb(168, 165, 165,0.2);" title="Coins"><img src="assets/img/coin.png"> <span id="coin-count" name="coin-count" style="font-size: 35px;">0</span></span>
<button onclick="ClickMoreGold()"><img src="assets/img/+1.png"></button>
<script src="script.js"></script>

The coin works fine on code pen so I am guessing The timer has a bug in it and my js is not getting my HTML doc which is weird.

Would you explain a little more about what is not working?

The count timer function has a bug in it and the functions are not responding on my webpage BUT when I put it into codepen they respond but the timer one has a bug in it so it does not.

Can you explain the bug in a little more detail. What should we be looking for? How is it supposed to work.

Also, in the HTML/JS you pasted above I don’t see the countTimer function being invoked anywhere. It’s going to be hard to test it if it isn’t being used :slight_smile:

You are naming the JS file script.js? And it is in the same directory as the HTML file?

yes it is all are correct don’t worry about the bug for now

Sorry, I’m not sure I understand your problem. I was able to get your code to run locally on my computer through a web browser. I saved the HTML and JS to files and then opened the HTML file in my browser. Every time I click the button the count increments by 1. If you can provide any more information about the problem you are having that would be great.

In my browser it doest increment by 1

That’s not really providing any more information than we already knew. Like I said, this is working fine for me, so I don’t see any problems. You’ll need to give us something more to go on. I already asked if you were naming the JS file correctly and if it is in the same directory as the HTML file and you said yes (at least I think you did). If that is true then there should be no problem opening the HTML file in your web browser and clicking on the button to increment the count.

Maybe you can describe exactly how you are running this on your computer? Perhaps you could put these files into github and give us a link to them? Are you seeing any errors in the dev tools console?

When you are looking at the page in your browser, what does the address bar say? Can you copy and paste that as a reply?

I fixed it it was a problem I fund.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.