There is such code:
<input class="field" type="number"> <input class="field" type="number"> <input class="field" type="number"> <button id="btn">Click</button> <p>XXX<p> (function() { let text = document.querySelector('p'); let fields = document.querySelectorAll('.field'); let btn = document.querySelector('#btn'); btn.addEventListener('click', function() { for(var i = 0; i < fields.length; i++) { text.textContent = fields[i].value; console.log(fields[i].value) } }) })() I need to write the values of each input's to the p element when I click on the button. But for some reason my code writes the value of only the last field, while the console displays the values of all fields. Where is the mistake?