Advertisement
Benargee

rainbowLog.js

Feb 29th, 2020
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. console.rainbow = function (str) {
  2.  
  3. let colors = [
  4.     "red",
  5.     "orange",
  6.     "yellow",
  7.     "green",
  8.     "blue",
  9.     "indigo",
  10.     "violet",//white in VS Code
  11. ]
  12. let color = "color";
  13.  
  14. let color_counter = 0;
  15. let color_direction = 1;
  16. let log_array = [];
  17. let log_string = "";
  18. for (var i = 0; i < str.length; i++){
  19.     char = str.charAt(i)
  20.     color = colors[color_counter];
  21.     let char_string
  22.     if(char != " "){
  23.         if (color_counter >= (colors.length - 1)) {color_direction = -1}
  24.         if (color_counter <= 0) {color_direction = 1}
  25.         color_counter += color_direction;
  26.         let color_string = `color:${color};font-size: large;`;
  27.         char_string = `%c${char}`;
  28.    
  29.         log_array.push(color_string);
  30.     } else {
  31.         char_string = char;
  32.     }
  33.     log_string += char_string;
  34. }
  35. log_array.unshift(log_string);
  36.  
  37. this.log(...log_array);
  38. };
  39.  
  40. //console.rainbow("Hello Fabulous World");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement