Student Code: map function not functioning We made this code in class:

 int red = 6;
  int green = 7;
  int blue = 8;
  int pot = A0;
  int potVal = 0;
  int chosenColor = 0;


void setup() {
  // put your setup code here, to run once:
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(pot, INPUT);
  Serial.begin (9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  potVal = analogRead(pot);
  chosenColor = map(potVal, 0, 1023, 1, 3);
  if(chosenColor = 1) {
    redCycle();
  }

  else {
    analogWrite(red,255);
  }

  if(chosenColor = 2) {
    greenCycle();
  }

  else {
    analogWrite(green,255);
  }


  if(chosenColor = 3) {
    blueCycle();
  }

  else {
    analogWrite(blue,255);
  }
  Serial.println(chosenColor);
  Serial.println(potVal);
  delay(500);
}

void redCycle() { 
    analogWrite(red,0);
  for(int i=0; i &lt; 256; i+=5) {
    analogWrite(red, i);
  }
}

void greenCycle() {
  analogWrite(green,0);
  for(int i=0; i &lt; 256; i+=5) {
    analogWrite(green, i);
  }
}

void blueCycle() {
  analogWrite(blue,0);
  for(int i=0; i &lt; 256; i+=5) {
    analogWrite(blue, i);
  }
}


When we open the serial monitor we find that chosenColor is always 3 regardless of what the potVal is reading. I am sure is something simple but we can't find where is the error. Please help.
As Edgar Bonet pointed out,  “chosenColor = 3 means 'let chosenColor take the value 3'”.  That is, your  potVal = analogRead(pot);  chosenColor = map(potVal, 0, 1023, 1, 3); sequence may very well be working, but by the time you get to Serial.println(chosenColor); you have changed chosenColor to 3.

First, the statement if(chosenColor = 1) {...} changes chosenColor to 1. Then the statement if(chosenColor = 2) {...} changes chosenColor to 2.  Finally, if(chosenColor = 3) {...} changes chosenColor to 3, just before you print out the current value of chosenColor.  

When you wish to compare two numeric values for equality, use == instead of =.