Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There can be multiple reasons why your input consistently gives a result of 0 when using .target.innerHTML:

  1. You might be trying to access the value of the input element using .innerHTML instead of .value. .value returns the current value of the input element, whereas .innerHTML returns the HTML content inside the element.

  2. You might not be converting the value of the input element from a string to a number before displaying it. When you use .innerHTML to display the value of the input element, it is displayed as a string. This may cause issues when you try to perform mathematical operations with the value.

  3. There might be some issues with the input itself, such as incorrect type or value. Make sure the input has the correct type attribute (e.g., number, text). Also, check if the value entered into the input is a valid number.

Overall, to get a better understanding of why you are consistently getting a result of 0, carefully examine your code and debug with console.log() statements to see if you are correctly accessing and manipulating the value of the input element.