Hey Community,
I have a lot of fun, solving the exercises.
I finaly found a solution for the “Title Case a Sentence”. It is not very elegant and way too long, but the code should work fine… But nonetheless it can not pass the tests. I tried it with every string, but it always returns the right data.
I could find another solution that works, but I really want to find out, what is wrong with the code, because I think understanding the bugs and solving them is a very important part of programming.
Any help is appreciated. Thank you in advance.
Ekko
var string = [];
function titleCase(str) {
var strLow = str.toLowerCase();
var words = strLow.split(" ");
for (var word in words) {
var x = words[word].split("");
x[0] = x[0].toUpperCase();
y = x.join("");
x = [y];
string.push(x);
}
str = string.join(" ");
return str;
}
titleCase("I'm a little tea pot");