-1

I'm creating a game played in the console and I would like to decorate my console.log messages to give them more flare.

Since I'm new to coding, I'm trying to learn to use template literals any time I console.log a message.

If I reverted to quotes and concatenation, I could style my console.log messages like so: console.log('%c some message' + someVar, 'color: red')

How can I style my console.log messages using template literals?

j08691
  • 197,815
  • 30
  • 248
  • 265

2 Answers2

0

You can use a template literal for the first argument to console.log instead of concatenation.

console.log(`%c some message ${someVar}`, 'color: red')

You can also use dynamic styles by using a template literal for the second argument as well.

Unmitigated
  • 46,070
  • 7
  • 44
  • 60
0

You can use this type of formatting.

console.log(`%c ${message} ${someVar}`, `color:${color}`)

Works like a charm.

Hultan
  • 1,191
  • 1
  • 10
  • 23