When I delete // it doesn't work.
The original sketch although slightly flawed, does work.
yes
This is actually expected. When the ESP8266 starts up, its ROM bootloader prints some diagnostic information. This data is printed at 74880 baud. So when you have the Serial Monitor set to a different baud rate (which is the correct thing to do in this case since your sketch communicates at 115200 baud) it is displayed as some garbage. You can simply ignore this garbage as the diagnostic information is only useful in special cases where the ESP8266 is misbehaving (e.g., resetting due to a watchdog timer timeout).
If you scroll the Serial Monitor output field all the way to the right, you should see the expected "What is your name?" message at the end of the line after all the garbage.
You can avoid that poor user experience by adding code to print a blank line or two before your first message:
void setup() {
Serial.begin(115200);
// Add some blank lines between the ROM bootloader output and the sketch output.
Serial.println();
Serial.println();
}
You will now get something like this:
rll��|�l�|�l�b|����r�b�b��nn�lnn���bp��lrlrlp�n��l��bn�|���b��nn�l��l`�nnl`nr���nbl�lp�n�r������bn�|�b��nn�l`�nnl`nr���nb��`r��nb��`��p�l`��n�l����n�r��n|�l�l`b��|r�l�n��n�l`��r�l�l��
What is your name?
You are welcome. I'm glad it is working now.
Regards,
Per
Mark the poster who solved it.