Index in an Action

I’ve used list comprehension to create an array that builds many rectangles at once.
When made clickable, it mentions that I can use “index” to reference the clicked index in the list.
Does anyone have an example of this in use?

I’m making them change colour individually on clicking so currently I reference each item of the array separately, but I would like to find a more efficient way.

This might be a very simple example of what you are looking for.

Here’s an example that drops the opacity of the list element that is clicked on. Graphing Calculator

Thank you! I was able to adapt it to create all of my rectangles in a single statement, and change the colour of each when clicked. Here’s my activity in its current form.

1 Like

Cool activity! Works nicely.