April_
April_

Reputation: 51

Discord.Js Problem adding a space after a +

ok so ik this is preety rookie but can someone help me out here. How do i add spaces in between +'s in code. message.channel.send("you baked" + random + "Cookies! :3 :cookie:") } It outputs BakedCookies all together due to the +'s

Upvotes: 1

Views: 232

Answers (3)

king
king

Reputation: 127

You can use + " " + to add spaces for these cases. However, I would prefer using Template strings like this:

message.channel.send(`You baked ${random} cookies! :3 :cookie`)

which would not require so many + and " ".

If your project is really slow though, using template literals actually slow speeds. Not by a lot but its something to note

Upvotes: 2

Botahamec
Botahamec

Reputation: 278

If you had three variables and needed spaces between them, you'd do:

message.channel.send(num1 + " " + num2 + " " + num3);

In your case, you're already using string literals, so you can just do:

message.channel.send("you baked " + random + " Cookies! :3 :cookie:");

Although, as Alex already mentioned, you can use ${random} in your string with Javascript. To do that, you can do this:

message.channel.send(`you baked ${random} Cookies! :3 :cookie:`);

Upvotes: 1

AlexZeDim
AlexZeDim

Reputation: 4362

Try this:

message.channel.send(`you baked ${random} Cookies! :3 :cookie:`)

Upvotes: 0

Related Questions