Last active
January 25, 2020 23:54
-
-
Save not-ivy/2575c34a610e82a847e9b09e77a50ece to your computer and use it in GitHub Desktop.
css-console-log
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
var rainbow = ["red", "yellow", "pink", "green", "purple", "orange", "blue"]; | |
function rainbowify(string) { | |
var splitString = string.split(""); | |
var formatString = ""; | |
var colorArguments = []; | |
for (var i = 0; i < splitString.length; ++i) { | |
formatString += "%c" + splitString[i]; | |
colorArguments.push("color : " + rainbow[i % rainbow.length]); | |
} | |
return [formatString].concat(colorArguments); | |
} | |
// output the array | |
console.log(rainbowify("test string")); | |
// Invoke console.log with the array as its arguments | |
console.log.apply(console, rainbowify("test string")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment