A JavaScript function that extends the String Prototype (bad practice, don't use this in production).
String.prototype.toAlternateCase = function () {
let r = "";
for (let i = 0; i < this.length; i++) {
r += i % 2 == 1 ? this[i].toUpperCase() : this[i].toLowerCase();
}
return r;
}
Add the code to your project (not recommended) and run it on a string:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit".toAlternateCase()
// => `"lOrEm iPsUm dOlOr sIt aMeT, cOnSeCtEtUr aDiPiScInG ElIt"`
Open the console and copy/paste this, press enter and see the magic happen:
String.prototype.toAlternateCase = function () {
let r = "";
for (let i = 0; i < this.length; i++) {
r += i % 2 == 1 ? this[i].toUpperCase() : this[i].toLowerCase();
}
return r;
}
document.querySelectorAll("*").forEach((el) => {
el.childNodes.forEach((child) => {
if (child.nodeType === 3) child.nodeValue = child.textContent.toAlternateCase()
})
})
eNjOy yOuR NeW StRiNgS iN aLtErNaTe cAsE