Code #2019

Created on November 16, 2025 at 12:53 PM by @generor 🌐 Public

Prompt: a loop for iterating the colors of the rainbow
Javascript
// rainbowColors.js
// This script iterates through the colors of the rainbow and logs each one to the console.

/**
 * An array containing the standard colors of the rainbow in order.
 * Each element is a string representing a color name.
 */
const rainbowColors = [
  'Red',
  'Orange',
  'Yellow',
  'Green',
  'Blue',
  'Indigo',
  'Violet'
];

console.log('Iterating through rainbow colors:');

/**
 * Loop through the `rainbowColors` array.
 * The `for` loop is used to access each color by its index.
 * `i` starts at 0 and increments until it reaches the total number of colors.
 */
for (let i = 0; i < rainbowColors.length; i++) {
  // Access the current color using its index 'i'.
  const currentColor = rainbowColors[i];
  
  // Log the current color to the console.
  // This demonstrates iteration and access to array elements.
  console.log(`- ${currentColor}`);
}

console.log('Rainbow iteration complete.');
🤖 Gemini 2.5 Flash ⚡ 0 Oomph