If I understood it correctly, the code overrides the className with every loop iteration.
b.className = "button"; is used to remove the "pressed" class.
To make it more clear, you could use the add and remove methods of classList property.
instead use buttonElement.classList.remove('pressed');
also utilize buttonElement.classList.add('pressed'); when it's needed.