I have been working on a bunch of JavaScript tutorials that are using some ES6. So far two of the lessons have been throwing the same error, and being new to JavaScript I'm still trying to understand the logic, and so not very good at debugging. I have tried using Babel to convert the ES6 code to plain JavaScript, thinking it was a browser issue, but the same error occurs.
Any help would be greatly appreciated.
The ES6 JavaScript
const inputs = document.querySelectorAll('.controls input');
function handleUpdate() {
const suffix = this.dataset.sizing || '';
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix);
}
inputs.forEach(input => input.addEventListener('change', handleUpdate));
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));
The "Babel" compiled JavaScript
var inputs = document.querySelectorAll('.controls input');
function handleUpdate() {
var suffix = this.dataset.sizing || '';
document.documentElement.style.setProperty('--' + this.name, this.value + suffix);
}
inputs.forEach(function (input) {
return input.addEventListener('change', handleUpdate);
});
inputs.forEach(function (input) {
return input.addEventListener('mousemove', handleUpdate);
});
The Error
inputs.forEach is not a function