S..
S..

Reputation: 335

How to console log ascii art

I'm trying to output ascii art via console log but since it includes escape characters I can't compile, how to prevent this?

The ascii art is something like this:

  ______                           _      
 |  ____|                         | |     
 | |__  __  ____ _ _ __ ___  _ __ | | ___ 
 |  __| \ \/ / _` | '_ ` _ \| '_ \| |/ _ \
 | |____ >  < (_| | | | | | | |_) | |  __/
 |______/_/\_\__,_|_| |_| |_| .__/|_|\___|
                            | |           
                            |_|           

console.log(``) fails and normal quotes will also complain about the escape characters.

Upvotes: 0

Views: 3026

Answers (2)

Ethicist
Ethicist

Reputation: 827

Another way would be to use a tool (instead of manually trying) to 'rectify' a string so it is logged as intended by escaping characters that prevent its interpretation as a string.

Execute this snippet to see your desired output:

console.log("  ______                           _      \r\n |  ____|                         | |     \r\n | |__  __  ____ _ _ __ ___  _ __ | | ___ \r\n |  __| \\ \\\/ \/ _` | \'_ ` _ \\| \'_ \\| |\/ _ \\\r\n | |____ >  < (_| | | | | | | |_) | |  __\/\r\n |______\/_\/\\_\\__,_|_| |_| |_| .__\/|_|\\___|\r\n                            | |           \r\n                            |_|           ")

An example of such a utility can be found here: https://www.freeformatter.com/javascript-escape.html

Additionally, here's an article that covers escape sequences: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#escape_notation

Upvotes: 4

Xeoth
Xeoth

Reputation: 1599

Put a \ before these characters.

Upvotes: 0

Related Questions