Ask coding questions

← Back to all posts
Username Not Displaying
CodingElf66

Username Not Displaying

Hello, Replit Community. If you run this, the program should first ask you for a username. However, if you then type a message, it doesn't display it onto the chat. So please help. I will be rewarding whoever that answers this 5 upvotes!

Answered by cjmatthy09 [earned 5 cycles]
View Answer
Voters
CodingElf66
Comments
hotnewtop
cjmatthy09

Change the (line 45 index.html)socket.emit(username + ': ' + 'chat message', input.value + ' ' + datetime);
to
socket.emit('chat message', username + ': ' + input.value + ' ' + datetime);
You're append to the name of the emitted "signal", meaning when you detect it, it won't match the socket.on('chat message') call. Instead, it is emitting "<username> : chat message" as the title instead of chat message.

CodingElf66

@cjmatthy09 Thanks!