"IF" statements not working - or "What am I doing wrong

I have been learning the Arduino for almost a whole week. I'm using the UNO. I plan on using the Teensy LC, and hence am using IDE 1.8.12.
I am trying to implement a tutorial program essentially copied from an on-line source. Other than changing a few names, the code is exactally as in the tutorial.
I can get it to parse and upload.
I can get the program to ask for and read the color input.
I can Serial.print the input color.
I CANNOT get inside my "if" statements.

[size=0.8em]Code: [url=https://arduinogetstarted.com/tools/arduino-code-highlighter]see how to post code[/url] [/size]

---



```
[size=0.8em]int DT = 1000; //Delay 1 sec
int rPin = 8; //red led in pin 8
int gPin = 9; //green in 9
int bPin = 10; //blue in 10
String msg1 = "What color LED would you like? (red, green, blue, or off) ";
String myColor;

void [color=#5E6D03]setup/color {
  // put your setup code here, to run once:
  Serial.[color=#D35400]begin/color;
  pinMode(rPin, OUTPUT); //set pinModes
  pinMode(gPin, OUTPUT);
  pinMode(bPin, OUTPUT);
}
void [color=#5E6D03]loop/color {
  Serial.println (msg1); //ask for color
  while (Serial.[color=#D35400]available/color == 0) { //wair
  }

myColor = Serial.[color=#D35400]readString/color; //read input from serial monitor
  Serial.[color=#D35400]println/color//THIS WORKS!

//None of my 'if' statements work ***
  if (myColor == "red") //THIS DOES NOT WORK
  {
    Serial.println("inside red loop");
    digitalWrite(rPin, HIGH);
    digitalWrite(bPin, LOW);
    digitalWrite(gPin, LOW);
    delay (DT);
  }
  if (myColor == "green") //THIS DOES NOT WORK
  {
    Serial.println("inside green loop");
    digitalWrite(rPin, LOW);
    digitalWrite(bPin, LOW);
    digitalWrite(gPin, HIGH);
    delay (DT);
  }
  if (myColor == "blue") //THIS DOES NOT WORK
  {
    Serial.println("inside blue loop");
    digitalWrite(rPin, LOW);
    digitalWrite(bPin, HIGH);
    digitalWrite(gPin, LOW);
    delay (DT);
  }
  delay (DT);
}[/size]
```

|

Nice try on the code tags, but you need to use the code tags as specified in item 7 of How to Use this Forum, and not the code highligther tool.

What happens if you set the monitor for no line endings? Your String comparisons don't taken any possible line endings sent with the color.

If you replace this line

Serial.println(myColor);  //THIS WORKS!

with

Serial.print( '"' );
Serial.print(myColor);  //THIS WORKS!
Serial.print( '"' );

You will see more than just the color inside the String.

Also, if you are just learning - forget about the String class and learn how to use C strings directly. It will save you in the long run.

if you selected the "line feed" termination option in the Serial Monitor then you may need to include the linefeed when testing the string

String s;

void setup (void)
{
    Serial.begin (115200);
}

void loop()
{
    if (Serial.available ())  {
        s = Serial.readString ();

        if (s == "joe")  {
            Serial.print   ("no LF");
            Serial.println (s);
        }
        else if (s == "joe\n")  {
            Serial.print ("LF");
            Serial.print   (s);
        }
    }
}