# Basic Algorithm Scripting - Title Case a Sentence

Tell us what’s happening:
Describe your issue in detail here.

the code outputs everything exactly like it should in the test case but it fails.

``````  **Your code so far**
``````
``````function titleCase(str) {
let newStr = str.split(" ");
let final = "";
for (let i = 0; i < newStr.length; i++) {
newStr[i] = newStr[i].toLowerCase();
newStr[i] = newStr[i].slice(0,1).toUpperCase() + newStr[i].slice(1);
final += newStr[i] + " ";

}
return final;
}

console.log(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT"));
// this literally output what it's supposed to.
``````
``````  **Your browser information:**
``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36`

Challenge: Basic Algorithm Scripting - Title Case a Sentence

Can somebody explain to me why this solution was not accepted when i tried it with all the test cases and it output the exact answer it wanted??

Hello there.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.

``````console.log("***" + titleCase("HERE IS MY HANDLE HERE IS MY SPOUT") + "***");
``````
1 Like

I ran into a similar problem once. Look at your line of code here:
`final += newStr[i] + " ";`

it is outputting a space at the end of the string as well

1 Like

oh I wrote my issue on bottom didn’t realize it should go up top. my bad

ahhhhhhhhh thats gotta be it thanks a bunch!

Ah, I missed it. A lot of posters just throw code at us and hope we know what they are thinking, so I get a little over eager with the automatic reply sometimes.

lol gotcha all good!

Mod edit: deleted code

and it works now thanks!

Happy for you!

I just need to let you know that I edited your last post to remove the code section. I just didn’t want to spoil the solution to other learners (we try to encourage people to solve things themselves)

lol makes sense my b.
thank you!

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.