Unleashing Creativity with Color the Rainbow on CodeHS
Embarking on a coding journey can be an exciting adventure, and CodeHS, a comprehensive learning platform, offers a plethora of engaging activities to enhance your skills. One such captivating exercise is "Color the Rainbow," a creative and interactive introduction to arrays and loops. Let's dive into this vibrant learning experience.
Understanding the Concept
At its core, "Color the Rainbow" is a simple yet powerful exercise that teaches the fundamentals of arrays and loops. Arrays are like containers that hold multiple values, in this case, colors. Loops, on the other hand, allow us to repeat a block of code multiple times, perfect for painting each color of the rainbow.
Getting Started with CodeHS
To begin, sign up or log in to your CodeHS account. If you're new, don't worry; CodeHS provides a user-friendly interface and plenty of resources to get you started. Once you're in, navigate to the "Color the Rainbow" exercise under the "Arrays" section.

Setting Up Your Environment
CodeHS uses a browser-based editor, making it accessible from any device with an internet connection. You'll see a code editor on the left, a preview pane on the right, and helpful hints and challenges below. Let's break down the initial code:
| Line | Code | Explanation |
|---|---|---|
| 1 | var colors = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]; | This line initializes an array called 'colors' with the names of the colors in the rainbow. |
| 2 | for (var i = 0; i < colors.length; i++) { | This line starts a 'for' loop that will iterate through each color in the array. |
| 3 | // TODO: Change this line | This is where you'll add your code to change the color of the rectangle. |
| 4 | } | This line ends the 'for' loop. |
Painting the Rainbow
Now that you understand the initial code, it's time to bring the rainbow to life. Replace the '// TODO: Change this line' comment with the following code:
```javascript document.getElementById("rectangle").style.backgroundColor = colors[i]; ```
This line of code selects the rectangle element by its ID, then changes its background color to the current color in the array.

Exploring Challenges
Once you've successfully painted the rainbow, you can explore the additional challenges offered by CodeHS. These challenges encourage you to experiment with different shapes, sizes, and even animations, deepening your understanding of arrays and loops.
Practice and Patience
Remember, learning to code is a journey, and like any journey, it's filled with ups and downs. Don't be discouraged if you encounter errors or challenges. Each mistake is an opportunity to learn and grow. Keep practicing, and soon you'll be painting rainbows with ease.
Happy coding, and enjoy your colorful journey on CodeHS!






















