Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
dmd-3475/mocking-sponge/js/main.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
26 lines (24 sloc)
721 Bytes
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
/** | |
* Get the editable instance. | |
*/ | |
let editable = document.querySelector('[contenteditable=true]'); | |
/** | |
* When focus is removed, run the `formatText` function | |
*/ | |
editable.addEventListener('blur', formatText); | |
/** | |
* Format the innerText of the SpongeBob meme | |
*/ | |
function formatText(event) { | |
/* Format the text | |
* Split the text into an array, for each character in the array, if the index of the letter is odd, | |
* return the letter uppercase, otherwise return it lowercase | |
* then join the array with no delimiter returning it to a normal string | |
*/ | |
this.innerText = this.innerText | |
.split('') | |
.map(function(letter, i) { | |
return i % 2 ? letter.toUpperCase() : letter.toLowerCase(); | |
}) | |
.join(''); | |
} |