how to use the Serial.readString() to type something from the keyboard??

the code below does not work when i type for example green or red or yellow, can anybody suggest a solution??

int green=8;
int yellow = 7;
int red = 4;
int ledon = 0;

void setup()
{

pinMode(8,OUTPUT);
pinMode(7,OUTPUT);
pinMode(4,OUTPUT);

Serial.begin(9600);

Serial.println("please select");
}

void loop()

{
String a ="";

if(Serial.available())
{

a = Serial.readString();

if (a=="green")

{
ledon = 1 ;
green = 8;
yellow= 7;
red = 4;
Serial.println("LED on");

}

if (a=="yellow")

{

ledon = 2;
green = 7;
yellow = 8;
red = 4;
Serial.println("LED on");

}

if (a=="red")

{

ledon=1;
green = 4;
yellow= 7;
red = 8;
Serial.println("LED on");

}

if (a=="off")

{
ledon = 0;
Serial.println("LED OFF");

}

}

if (ledon)

{

digitalWrite(green,HIGH);
digitalWrite(red,LOW);
digitalWrite(yellow,LOW);

}

else

{
digitalWrite(8,LOW);
digitalWrite(4,LOW);
digitalWrite(7,LOW);

}

}

How anyone can work with code laid out like that is beyond me

Here it is formatted much better using Aoto Format in the IDE and in code tags here to make it easier to copy to an editor

int green = 8;
int yellow = 7;
int red = 4;
int ledon = 0;

void setup()
{
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(4, OUTPUT);
  Serial.begin(115200);
  Serial.println("please select");
}

void loop()

{
  String a = "";
  if (Serial.available())
  {
    a = Serial.readString();
    Serial.print(">");
    Serial.print(a);
    Serial.println("<");
    if (a == "green")
    {
      ledon = 1 ;
      green = 8;
      yellow = 7;
      red = 4;
      Serial.println("LED on");
    }
    if (a == "yellow")
    {
      ledon = 2;
      green = 7;
      yellow = 8;
      red = 4;
      Serial.println("LED on");
    }
    if (a == "red")
    {
      ledon = 1;
      green = 4;
      yellow = 7;
      red = 8;
      Serial.println("LED on");
    }
    if (a == "off")
    {
      ledon = 0;
      Serial.println("LED OFF");
    }
  }
  if (ledon)
  {
    digitalWrite(green, HIGH);
    digitalWrite(red, LOW);
    digitalWrite(yellow, LOW);
  }
  else
  {
    digitalWrite(8, LOW);
    digitalWrite(4, LOW);
    digitalWrite(7, LOW);
  }
}

Eagle eyed readers will note 3 lines of printing added for debugging purposes to see what readString() has returned

OP. What have you got the Line ending set to in the Serial monitor ?
What happens if you use a different setting for Line Ending ?
Does the output from the debugging lines change perhaps ?