Created
December 5, 2016 02:23
-
-
Save kellylougheed/2512590f9954e5b27fdfb2274e0adf43 to your computer and use it in GitHub Desktop.
Colors every other word in a string by wrapping <span> tags around it.
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
function colorEveryOther(str) { | |
var arr = str.split(" "); | |
for (var i = 0; i < arr.length; i++) { | |
if (i % 2 === 0) { | |
arr[i] = "<span>" + arr[i] + "</span>"; | |
} | |
} | |
var newStr = arr.join(" "); | |
return newStr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment