Problem using function to condense code to fade up/down 6xLED

I am trying to control 6xLEDs from analog pins 3 to 11 which fade up and down at different rates. I have an existing code which works fine, however it is very long winded. I have attempted to condense the code using an array for fadeAmount and a function when declaring the 6x output pins.

The code will upload (to Arduino Uno) without any errors and begin the phasing up/down, however it will stop running after about 10 seconds with some LEDs left on and some off. I cannot work out why it is doing this, but I expect there is an error in my logic somewhere.

I have included the original (working) code and the condensed code below.

Any help/suggestions would be much appreciated.

EXISTING CODE:

int led_1 = 9;           
int led_2 = 10;
int led_3 = 11;
int led_4 = 6;
int led_5 = 5;
int led_6 = 3;
int brightness_1 = 0;  
int brightness_2 = 100;
int brightness_3 = 200;
int brightness_4 = 150;
int brightness_5 = 250;
int brightness_6 = 50;
int fadeAmount_1 = 2;  // varying fadeAmount
int fadeAmount_2 = 5;
int fadeAmount_3 = 6;
int fadeAmount_4 = 3;
int fadeAmount_5 = 4;
int fadeAmount_6 = 3;


void setup()  { 
 
  pinMode(led_1, OUTPUT);
  pinMode(led_2, OUTPUT);
  pinMode(led_3, OUTPUT);
  pinMode(led_4, OUTPUT);
  pinMode(led_5, OUTPUT);
  pinMode(led_6, OUTPUT);
  
  // the loop routine runs over and over again forever:
void loop()  { 
  // set the brightness of pins
  analogWrite(led_1, brightness_1); 
 analogWrite(led_2, brightness_2);
analogWrite(led_3, brightness_3); 
analogWrite(led_4, brightness_4);
analogWrite(led_5, brightness_5);
analogWrite(led_6, brightness_6);

  // change the brightness for next time through the loop:
  brightness_1 = brightness_1 + fadeAmount_1;
  brightness_2 = brightness_2 + fadeAmount_2;
  brightness_3 = brightness_3 + fadeAmount_3;
  brightness_4 = brightness_4 + fadeAmount_4;
  brightness_5 = brightness_5 + fadeAmount_5;
  brightness_6 = brigtness_6 + fadeAmount_6;

  // reverse the direction of the fading at the ends of the fade: 
  if (brightness_1 == 0 || brightness_1 == 255) {
    fadeAmount_1 = -fadeAmount_1 ;
  }else if (brightness_2 == 0 || brightness_2 == 255){
    fadeAmount_2 = -fadeAmount_2;
  }else if (brightness_3 == 0 || brightness_3 == 255){
    fadeAmount_3 = -fadeAmount_3;
  }else if (brightness_4 == 0 || brightness_4 == 255){
  fadeAmount_4 = -fadeAMount_4;
  }else if (brightness_5 == 0 || brightness_5 == 255){
  fadeAmount_5 = -fadeAmount_5;
  }else if (brightness_6 == 0 || brightness_6 == 255){
  fadeAmount_6 = -fadeAMount_6
  }  
  delay(50);                            
}
int fadeArray[]={2,5,6,3,4,3};
int Index = 1;
int led = 3;
int brightness = 100;


void setup(){
  for (int x = 3;x%11;x++){
    pinMode(x, OUTPUT);
  }
}
  
void loop(){
  for(int x=3;x%11;x++);
  analogWrite(led, brightness);{
      led++;
    }
    
    brightness = brightness + fadeArray[Index];{
      Index ++;
    }
    
    if (brightness == 0 || brightness == 255){
      fadeArray[Index] = -fadeArray[Index];
      Index ++;
    }
    delay(50);
  }

from analog pins 3 to 11

They are not analogue pins they are digital ones. They use PWM
http://www.thebox.myzen.co.uk/Tutorial/PWM.html

 for(int x=3;x%11;x++);

The semicolon at the end of this line makes it not work at all.

Learn to use arrays

http://www.thebox.myzen.co.uk/Tutorial/Arrays.html

You don't have an array for your pins and your for statements do not appear to have a check to finish them

int ledpins[] = {9,10,11,6,5,3};
int brightness[] = {0,100,200,150,250,50};
int fadeamount[] = {2,5,6,3,4,3};

void setup(){
  for (int x = 0; x< 6;x++)
  {
    pinMode(ledpins[x], OUTPUT); 
  }
}

In your example I would use mutiple arrays, 1 for pins, 1 for the fade amount for each led, 1 for the brightness for each led

void loop()
{
 for (int x = 0; x< 6; x++)
 {
  analogWrite(ledpins[x], brightness[x]);
  brightness[x] = brightness[x] + fadeamount[x];
  if (brightness[x] <= 0)
  { 
    brightness[x] = 0;
    fadeamount[x] = abs(fadeamount[x]);
  }
  if (brightness[x] >= 255)
  {
    brightness[x] = 255;
    fadeamount[x] = -abs(fadamount[x]);

  }
 }
}

Your check for brightness at min or max (0,255) in sample code did not detect a possibility of not hitting 0 or 255 (sample code for fade used a fade amount of 5 so it hit the 0 and 255 amounts).