Need help with buttons and array

hey guys I have a problem. I want to make a programm where i can press buttons to add something to an array which i can read, so like an numpad. the layout and all is great but when i want to add the function that when i press a button the number is add to the array nothing happens. :frowning:
Here is my code without that function in the webeditor:

Please help me. :wink:

1 Like

Would this do what you want (add it right above k++)?

let index = k;
1 Like

When I copy-paste it there this massage comes up in the console:

TypeError: buttons[k].button is undefined (sketch: line 18)

Sorry, my bad. I changes something in the class as well: a getter to the button.

The class now returns a reference to the HTML button by means of the getter. that is used to attached the mousePressed to the button.


heyy i just wanted to thank you because it worked and I forgot to Thank you. :hugs:


You’re welcome :grinning: (was away for a bit…)