# Randomize Colors & Buttons as Arrays

**URL:** <https://forum.code.org/t/randomize-colors-buttons-as-arrays/39142>\
**Category:** CS Principles\
**Tags:** applab, csd-unit-2, csd-unit-1, csd-unit-3\
**Created:** [March 13, 2024, 11:29pm UTC](https://forum.code.org/t/randomize-colors-buttons-as-arrays/39142 "2024-03-13T23:29:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddsteam](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@ddsteam](https://forum.code.org/u/ddsteam)\
**Post date:** [March 13, 2024, 11:29pm UTC](https://forum.code.org/t/randomize-colors-buttons-as-arrays/39142/1 "2024-03-13T23:29:50Z")

</div>

My student is trying to make it so that the buttons in her program show up with random colors with a single function or loop. I know how to make lists and arrays, but App Lab doesn’t want to create a list that can be called back as IDs–only strings and variables. I know we can use the setProperty function with the rbg set to the randomNumber blocks, but I’m having a hard time getting the buttons to be treated as a list. I want to create a single ID for all of the buttons and I can’t really do that without using const which isn’t available on App Lab. Help?

 ![random colors code](https://us1.discourse-cdn.com/flex016/uploads/codeorgforum/original/2X/7/73e135d0b7108053d6ff5866e5029d517e434e04.png)

---

<div class="post-metadata">

**Author:** ![madeline\_r\_burton](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/madeline_r_burton/32/5037_2.png) [@madeline\_r\_burton](https://forum.code.org/u/madeline_r_burton)\
**Post date:** [March 14, 2024, 3:41am UTC](https://forum.code.org/t/randomize-colors-buttons-as-arrays/39142/2 "2024-03-14T03:41:42Z")

</div>

Your request reminds me of a lesson that existed in the previous version of the course. By being intentional about the name of the element, such as button1, button2, button3 etc. you can create a variable that uses the for loop’s iterator to generate the string of the button name. (perhaps something like “button” + i) then this variable can be used in the call to setProperty.

Here is the [practice level](https://studio.code.org/s/csp5-2022/lessons/7/levels/8?section_id=4788845) from 2022. Perhaps this will meet the students’ needs?
