Here is my HTML code:
<button id="remove10" onclick="subtract()">Remove 10</button>
<div id="final-answer">Final answer</div>
Here is my Javascript code:
var startingNumber = 100;
var minus10 = document.querySelector("#remove10");
function subtract() {
startingNumber = startingNumber - 10;
}
minus10.onclick = subtract();
document.querySelector("#final-answer").innerHTML = startingNumber;
My goal is that every time the "Remove 10" button is clicked it subtracts 10 from the initial value of 100 and changes the displayed text to reflect the answer. So 1st click - show 90, 2nd click - show 80, etc.
The code I currently have shows the number as 90 from the start and nothing happens when I click the button. What am I doing wrong here?