Title Case a Sentence Need help in 1 line Only

Tell us what’s happening:

Hi guys,I only need to change that line but i’ve tried everything and nothin logical seems to work
" for(let i=0;i<InputArraySplitted.length;i++) "

Your code so far



function titleCase(str) {
let InputArraySplitted=str.split(" “);
console.log(InputArraySplitted)
console.log(”\n")
let EachWord="";
let Eachletter=[];
let LettersAfterEdit="";
let StringAfterEdit=[];
let Result="";
for(let i=0;i<InputArraySplitted.length;i++)
{
EachWord=InputArraySplitted.shift();
console.log(EachWord)
Eachletter=EachWord.split("");
console.log(Eachletter)
// Upper/lower case for each word//
Eachletter[0]=Eachletter[0].toUpperCase();
if(Eachletter.length>1)
{
for(let j=1;j<Eachletter.length;j++)
{
Eachletter[j]=Eachletter[j].toLowerCase();
}
}
LettersAfterEdit=Eachletter.join("");
StringAfterEdit.push(LettersAfterEdit)
EachWord="";
Eachletter=[];
// Upper/lower case for each word//
}
return Result=StringAfterEdit.join(" ");
}

console.log(titleCase(“I’m a little tea pot”));


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/title-case-a-sentence

How do you know if you have to change only one line? What results are you getting?

I can’t copy your code and run in console. Can you just make your code preformatted instead? Select your code and hit preformatted icon in the editor.

1 Like

i have edited my post…i know it’s only one line because i used console.log to see the result of each part including the final result

I still can’t grab your code. It won’t let me copy it.

i removed the spoiler tags…now you can copy…in my last post someone told me to put the spoiler tags on if i post correct or almost correct solution

He’s correct. Spoiler tags should be used to hide a correct code but since your code isn’t and I need to copy it to run it, it should be fine.

Here is the output it gives. So there is actually something more wrong with your code. Try doing console logs more often to see where your error is at.

image

Also, doing something like this is a bad example,

return Result = StringAfterEdit.join(" ");

You could do this

let Result = StringAfterEdit.join(" ");
return Result

Or simply

return StringAfterEdit.join(" ");