Javascript String upperLower()
String.prototype.upperLower = function () { var result = []; var splited = this.split(""); for (var i = 0; i < splited.length; i++) { if (i % 2 === 0) { result.push(splited[i].toLowerCase()); } else {//from ww w. j a v a 2s . c om result.push(splited[i].toUpperCase()); } } return result.join(''); } var funnyText = "Smiesznie".upperLower(); console.log(funnyText);
String.prototype.upperLower = function () { var result = []; var splited = this.split(" "); //pojedyncze wyrazy tablica for (var i = 0; i < splited.length; i++) { var singleWord = splited[i];//pojedynczy wyraz var singleWordResult = ''; for (var j = 0; j < singleWord.length; j++) { if (j % 2 === 0) { singleWordResult += singleWord[j].toLowerCase(); } else {/*from w ww . ja va2s . co m*/ singleWordResult += singleWord[j].toUpperCase(); } } result.push(singleWordResult); } return result.join(' '); } var funnyTextWithSpace = "Javascript jest super".upperLower(); console.log(funnyTextWithSpace);