The issue
I wrote a function to demonstrate how to format Chrome developer console console.log() messages in a variety of ways. However, the one I'm having trouble with is printing a variable on the left with a color scheme, then a string in the middle with no styling, followed by another variable that is styled. Here is a graphic to illustrate:
Also, this HTML/CSS code will demonstrate what I'm trying to produce in the developer console:
<p>Array values printed out (equals sign not formatted):</p>
<span style="background: #ffa600; color: #ffe4b3;">Array[index0]</span> = <span style="background: yellow; color: black; font-style: italic;">http://www.google.com</span><br>
<span style="background: #ffa600; color: #ffe4b3;">Array[index1]</span> = <span style="background: yellow; color: black; font-style: italic;">http://www.pinterest.com</span><br>
<span style="background: #ffa600; color: #ffe4b3;">Array[index2]</span> = <span style="background: yellow; color: black; font-style: italic;">http://www.facebook.com</span><br>
<p>Multiple combinations of formatted and non formatted text:</p>
<p>
<span style="background:red;">Red</span>
<span> and </span>
<span style="background:aliceblue">AliceBlue</span>
<span> OR </span>
<span style="color:forestgreen; font-style: italic; font-weight: bold;">Forest Green</span>
<span style="background: orange">Orange</span>
<span>, also this: <span>
<span style="background:pink; color: brown"> Error Styling </span>
<span>, etc ...</span>
</p>
What I've tried that didn't work
This code from christianvuerings in Colors in JavaScript console works to print two different styles back-to-back:
console.log("%cHello, "+"World","color:red;","color:blue;")
I based my attempts on that code. The trouble is, Christian's code doesn't account for having non-formatted code sandwiched between formatted code, nor for having multiple variables. I made many tries to find the right combination of code and ordering, but the three most promising (to me) were these:
console.log("%c%s"+" is "+"%c%d"+"years old.", "color:red","Bob", "color:blue", 42).
console.log("%c%s"," is ","%c%d","years old.", "color:red","Bob", "color:blue", 42).
console.log("%c%s is %c%d years old.", "color:red", "Bob", "color:blue", 42).
My question
How can I print console.log() messages with multiple combinations of formatted and non-formatted code all on the same line?