String comparison not working

I'm trying to code a morse code converter that convert text to morse code, but I'm trying to just do alphabets right now. But why won't this works?? I have no idea what to do. I'm new to Arduino and this forum.

void loop() {
// put your main code here, to run repeatedly:
while (Serial.available()) { //cek jika input ada
USERINPUT = Serial.readString(); //menyimpan input ke variable
Serial.print(USERINPUT);
if (USERINPUT == "E") {
CONVERT += ".";
Serial.print(CONVERT);
}
if (USERINPUT == "T") {
CONVERT += "-";
}
if (USERINPUT == "I") {
CONVERT += "..";
}
if (USERINPUT == "A") {
CONVERT += ".-";
}
if (USERINPUT == "N") {
CONVERT += "-.";
}
if (USERINPUT == "M") {
CONVERT += "--";
}
if (USERINPUT == "S") {
CONVERT += "...";
}
if (USERINPUT == "U") {
CONVERT += "..-";
}
if (USERINPUT == "R") {
CONVERT += ".-.";
}
if (USERINPUT == "W") {
CONVERT += ".--";
}
if (USERINPUT == "D") {
CONVERT += "-..";
}
if (USERINPUT == "K") {
CONVERT += "-.-";
}
if (USERINPUT == "G") {
CONVERT += "--.";
}
if (USERINPUT == "O") {
CONVERT += "---";
}
if (USERINPUT == "H") {
CONVERT += "....";
}
if (USERINPUT == "V") {
CONVERT += "...-";
}
if (USERINPUT == "F") {
CONVERT += "..-.";
}
if (USERINPUT == "L") {
CONVERT += ".-..";
}
if (USERINPUT == "P") {
CONVERT += ".--.";
}
if (USERINPUT == "J") {
CONVERT += ".---";
}
if (USERINPUT == "B") {
CONVERT += "-...";
}
if (USERINPUT == "X") {
CONVERT += "-..-";
}
if (USERINPUT == "C") {
CONVERT += "-.-.";
}
if (USERINPUT == "Y") {
CONVERT += "-.--";
}
if (USERINPUT == "Z") {
CONVERT += "--..";
}
if (USERINPUT == "Q") {
CONVERT += "--.-";
}
Serial.println("Converted to morse code: ");
Serial.print(CONVERT);
}

}

It's too bad that you chose to use a quote instead of code tags.
It's too bad that you only showed part of the code.
It's too bad that you didn't read the locked posts at the top of this forum about how to post properly.

"E" is a string, the char E followed by the char null. You would use strcmp(...) or perhaps strncmp(...) to compare two strings.
'E' is a char. Two char_s may be compared using == .

You probably intended

    if (USERINPUT == 'E') {

but because you omitted the declaration of USERINPUT it is merely a wild guess.

By the way, the conventional way of spelling USERINPUT is userInput. This is sometimes called camelcase with a leading lower case character.

By the way, I would guess that CONVERT (which would conventionally be called convert) is declared as a String. String (capital S) is considered bad in the environment of most Arduinos. It is preferable to use a string (lowercase s).

You neglected to tell us what Arduino you have.

vaj4088:
By the way, the conventional way of spelling USERINPUT is userInput. This is sometimes called camelcase with a leading lower case character.

Camel case is usually stylized as camelCase. :grin:

(Fully aligned on the rest)

what does it do?

CONVERT must be a String which is a object. I don't believe you can pass a String object to Serial.print(). Serial.print() expects a string (array of chars) or numeric value. do you need to use c_str() to convert the String object to a char array?

also, don't you need a pause between morse code characters?

I don’t believe you can pass a String object to Serial.print()

.Of course you can.