3 buttons, 2 working buttons

I have three buttons done differently, but one doesn’t work. I’m sure it’s a simple answer. Can someone give me a quick explanation of why the O button doesn’t do anything?

If I’m not mistaken it’s because your inline function call is calling a function that it doesn’t have access to—the function three() is currently scoped to inside the jQuery’s ready() method. Since it looks like you are just testing at this stage, move the function three() outside of the ready() method and click again! Good luck! :smile:

1 Like

Check your browser’s console for an error. The function three is only defined inside your document.ready callback function and is not in the global scope where the onclick event handler can access it.

If you are going with plain JavaScript, there is another more recognized way of accomplishing the same thing.

  document.getElementById("reset").addEventListener("click", function() {
    exoh = 0;
    console.log(exoh)
  });

FYI - If an element has an id which has no special characters (i.e.no dashes) such as your button with id=“reset”, then you can simply reference the element directly by using the id.

  reset.addEventListener("click", function two() {
    exoh = 0;
    console.log(exoh)
  });

or using your original plain JavaScript version:

  reset.onclick = 
    function two(){
    exoh = 0;
    console.log(exoh)
  }
1 Like

They wont let me post anything under twenty characters, so I had to write all this to say thanks.

1 Like