Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Colors.js: Proper syntax for adding a color to a variable (string)?

In addition to my static message (which displays just fine), how would I make the variable named 'port' green in this console.log?

console.log('Express app started on port '.green + port);

I don't see anything about adding colors to variables in the docs, and of course if I just add .green to port, it will look for the .green element of the port var which will be undefined.

Using: https://github.com/Marak/colors.js

like image 794
k00k Avatar asked Dec 29 '11 19:12

k00k


People also ask

How To color a string in js?

In JavaScript, fontcolor() is a string method that is used to create the HTML <font> element and specify a font color. Because the fontcolor() method is a method of the String object, it must be invoked through a particular instance of the String class.

What is true about the variables in JavaScript?

Variable means anything that can vary. In JavaScript, a variable stores the data value that can be changed later on. Use the reserved keyword var to declare a variable in JavaScript.


1 Answers

colors.js modifies the string object -- try

port.toString().green
like image 172
mike Avatar answered Nov 10 '22 01:11

mike