Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- console.rainbow = function (str) {
- let colors = [
- "red",
- "orange",
- "yellow",
- "green",
- "blue",
- "indigo",
- "violet",//white in VS Code
- ]
- let color = "color";
- 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)
- 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");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement