SOLVED: Converting "forEach" to "for loop" some help

I want to convert this to for loop, how would I do that?


  function initButton(wrapperSelector) {
    const wrapper = document.querySelector(wrapperSelector);
    const buttons = wrapper.querySelectorAll(".playButton");
    buttons.forEach(function (button) {
      button.addEventListener("click", playButtonClickHandler);
      button.addEventListener("mouseover", playButtonMouseoverHandler);
      button.addEventListener("mouseout", playButtonMouseoutHandler);
     });
  }
  initButton(".wrapc");
}());

how would you do that?

buttons is what is being iterated over

What is that supposed to mean?

What are you saying?

what have you tried to do?

These are examples of for loop codes I have done.

   function pauseAllButtons() {
      let buttons = document.querySelectorAll(".playButton");
      for (let i = 0; i < buttons.length; i++) {
         if (isPlaying(buttons[i])) {
            showPlayButton(buttons[i]);
         }
      }
   }


   function hideAllButtons(button) {
      const buttons = button.querySelectorAll(".play, .pause, .speaker");
      for (let i = 0; i < buttons.length; i++) {
         hide(buttons[i]);
      }
   }

and can’t you do sonething similar instead of the forEach?

Got it.


  function initButton(wrapperSelector) {
    const wrapper = document.querySelector(wrapperSelector);
    const buttons = wrapper.querySelectorAll(".playButton");
    for (let i = 0; i < buttons.length; i++) {
      let button = buttons[i];
      button.addEventListener("click", playButtonClickHandler);
      button.addEventListener("mouseover", playButtonMouseoverHandler);
      button.addEventListener("mouseout", playButtonMouseoutHandler);
    }
  }
  initButton(".wrapc");
}());

awesome!

happy coding!