I have looked at numerous questions already on here and I haven't been able to find a similar problem. I am trying to give a button a function that updates a variable (specifically a number, i.e. - button press >> 0 becomes 1) and write it to the innerHTML of a div. It updates in an alert, but it doesn't update the innerHTML.
var example = 0;
var exampleDiv = document.getElementById('exampleDiv');
function buyExample() {
example += 1;
}
exampleDiv.innerHTML = 'You have ' + example + ' examples.';
The number displayed on the webpage is 0.
exampleDiv.innerHTML = ...to be inside thebuyExamplefunction, but you haven't really shared enough code for anyone to be sure.buyExample, so it is never increased.exampleDiv.innerHTML = 'You have ' + example + ' examples.';goes inside buyExample() function.