BEGINING OF THE FUNCTION
function howMany(selectObject) {
let numberSelected = 0;
for (let i = 0; i < selectObject.options.length; i++) {
if (selectObject.options[i].selected) {
numberSelected++;
}
}
return numberSelected;
}
END OF THE FUNCTION
const btn = document.getElementById('btn');
btn.addEventListener('click', () => {
const musicTypes = document.selectForm.musicTypes;
console.log(`You have selected ${howMany(musicTypes)} option(s).`);
});
And what is inside the function is like, the function is a machine and what is inside the function are the pieces of the mechanism that make the function make an operation (work) like a machine, so if the machine doesn't work maybe the mechanism inside isn't assembled properly.
And the part of the code that is in grey are we providing the navigation buttons to operate the machine, so maybe if the machine doesn't work maybe is because the buttons aren't operating the machine, and also basically the normal the part that we are operating the machine the internal itens of the mechanism aren't visible by here, is like this the normal is don't make sense you put in the operation handlers the mechanism of the machine, you see that the inner items of the function I marked and they aren't repeated out of the function.
Rute Bezerra de Menezes Gondim
No comments:
Post a Comment