0

I'm working on a chat app built using HTML, Javascript, Node.js and Socket.io. I want the name of the user that is stored in data.name to appear bold. I tried adding * to the start and end of the variable but it only added asterisk as a text.

What am I doing wrong?

socket.on('receive', data => {
  var msger = `${data.message}`;
  console.log(msger.length);
  if (name.length == 0) {
    append(`Anonymous: ${data.message}`, 'left');
  } else {
    append(`${data.name}: ${data.message}`, 'left');
  }
});
Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
Esjee
  • 25
  • 7
  • Please post the code in your question, not in an external image. – Mike May 25 '21 at 16:21
  • Potential duplicate of [Use bold tag to send my message from node server](https://stackoverflow.com/questions/51379281) – Mr. Polywhirl May 25 '21 at 16:34
  • Please show the code for the `append()` method. What does it do? Where is this text being displayed? If it's being displayed in a browser, then you will want to wrap it in the HTML tag `Your text`. – jfriend00 May 25 '21 at 17:23

2 Answers2

1

You could use the bold() method on that variable. This should wrap the text in a bold tag and then return it

` ${data.name.bold()} `

Also, I'm pretty sure you might be able to get away with just wrapping it in a b tag.

` <b> ${data.name} </b> `
Peter Dev
  • 46
  • 3
0

You can write as follows.

append(`<strong>${data.name}</strong>: ${data.message}`, 'left');

This way name is written in bold.