Last active
January 1, 2022 17:24
-
-
Save Benargee/abf0ceba9baa92a9a2a2d0f2952b6928 to your computer and use it in GitHub Desktop.
A console.log with a little more... flair.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.rainbow = function (str) { | |
const colors = [ | |
"red", | |
"orange", | |
"yellow", | |
"green", | |
"blue", | |
"indigo", | |
"violet",//white in VS Code | |
] | |
let color_counter = 0; | |
let color_direction = 1; | |
let log_array = []; | |
let log_string = ""; | |
for (var i = 0; i < str.length; i++){ | |
char = str.charAt(i) | |
let color = colors[color_counter]; | |
let char_string; | |
if(char != " "){ | |
if (color_counter >= (colors.length - 1)) {color_direction = -1}; | |
if (color_counter <= 0) {color_direction = 1}; | |
color_counter += color_direction; | |
let color_string = `color:${color};font-size: large;`; | |
char_string = `%c${char}`; | |
log_array.push(color_string); | |
} else { | |
char_string = char; | |
} | |
log_string += char_string; | |
} | |
log_array.unshift(log_string); | |
this.log(...log_array); | |
}; | |
//console.rainbow("Hello Fabulous World"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment