**
I think my code is correct and its returning the same values as mentioned in task still its not approving. **
Can anyone explain what I am doing wrong in this code
Your code so far
function titleCase(str) {
let splittedStr = str.toLowerCase().split(" ")
let upperStr = ''
for (let i = 0; i < splittedStr.length; i++) {
let newStr = splittedStr[i].replace(splittedStr[i][0], splittedStr[i][0].toUpperCase())
upperStr += newStr + ' '
}
console.log(upperStr)
return upperStr;
};
titleCase("I'm a little tea pot");
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36
Challenge: Basic Algorithm Scripting - Title Case a Sentence
Still its not working but found a solution there was a empty space after the word
Here is the function
function titleCase(str) {
let splittedStr = str.toLowerCase().split(" ");
let upperStr = ‘’;
for (let i = 0; i < splittedStr.length; i++) {
let word = splittedStr[i];
let capitalizedWord = word.charAt(0).toUpperCase() + word.slice(1);
upperStr += capitalizedWord + ’ ';
}
return upperStr.trim();
}
function titleCase(str) {
let splittedStr = str.toLowerCase().split(" ")
let upperStr = ‘’
for (let i = 0; i < splittedStr.length; i++) {
let newStr = splittedStr[i].replace(splittedStr[i][0], splittedStr[i][0].toUpperCase())
The point of my suggestion about changing the console log was not to give you the code to solve your issue but rather to make you see the issue that needed to be fixed. It looks like that worked.