function LetterChanges(str) {
var iLetters = str.split('');
var newStr = [];
for (var i = 0; i < str.length; i++) {
if (/[a-y]/ig.test(iLetters[i])) {
newStr[i] = String.fromCharCode(iLetters[i].charCodeAt(0) + 1);
if (/[aeiou]/ig.test(newStr[i])) {
newStr[i] = newStr[i].toUpperCase();
}
} else if (/[z]/ig.test(iLetters[i])) {
newStr[i] = "A";
} else if (/[^A-Z]/ig.test(iLetters[i])) {
newStr[i] = iLetters[i];
}
}
return newStr.join('');
}
function letterChanges(str) {
var newString = "",
code,
length,
index;
for (index = 0, length = str.length; index < length; index += 1) {
code = str.charCodeAt(index);
switch (code) {
case 90:
code = 65;
break;
case 122:
code = 97
break;
default:
if ((code >= 65 && code < 90) || (code >= 97 && code < 122)) {
code += 1;
}
}
newString += String.fromCharCode(code);
}
return newString.replace(/[aeiou]/g, function (character) {
return character.toUpperCase();
});
}
console.log(LetterChanges("Then capitalize every vowel in this new string (a, e, i, o, u) and finally return this modified string."));
console.log(letterChanges("Then capitalize every vowel in this new string (a, e, i, o, u) and finally return this modified string."));
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.