Tell us what’s happening:
so far, I am seeing solutions like this.
String.prototype.replaceAt = function(index, character) {
return this.substr(0, index) + character + this.substr(index+character.length);
};
function titleCase(str) {
var newTitle = str.split(' ');
var updatedTitle = [];
for (var st in newTitle) {
updatedTitle[st] = newTitle[st].toLowerCase().replaceAt(0, newTitle[st].charAt(0).toUpperCase());
}
return updatedTitle.join(' ');
}
I came up with this
Your code so far
function titleCase(str) {
var low = str.toLowerCase('');
var splitting = low.split(' ');
var upperI = splitting[0];
var upperArrI = upperI[0].toUpperCase();// turns i in i'm into I
var upperA = splitting[1];
var upperArrA = upperA.toUpperCase();// adds upper case to the a after the word i'm
var upperL = splitting[2];
var upperArrL = upperL[0].toUpperCase();
var upperT = splitting[3];
var upperArrT = upperT[0].toUpperCase();
var replaceFirst = str.replace(str[0],upperArrI).replace(str[4],upperArrA).replace(str[6],upperArrL);
var eraseHalf = str.substr(13);// gets rid of str first 13 strings
var replaceSecond = eraseHalf.replace(eraseHalf[0],'T').replace(eraseHalf[4],'P');
//reversing str, targetting the first two arrays and joining them..
//the final variable of the following variables will be joined to replaceSecond
// var reverseStr = splitting.reverse('');
// var reverseSplitting_1 = reverseStr[0];
// var reverseSplitting_2 = reverseStr[1];
// var reverseSplittingJoin = reverseSplitting_1.concat(' ',reverseSplitting_2);
//var reverseStr - reverseSplittingJoin are arbitrary
var first_second = replaceFirst.replace('tea pot',replaceSecond); //replaces tea pot with Tea Pot
return first_second;
}
titleCase("I'm a little tea pot");
can a solution be created from the mess ive made?
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
.
Link to the challenge: