Basic Algorithm Scripting - Title Case a Sentence

Tell us what’s happening:
Describe your issue in detail here.
So, my result is exactly, word by word what the quiz asked for, but for some reason, it doesn’t accept this answer? They also didn’t ask for specific ways to do it so, I am not sure why they don’t accept my answer,

1. I make every word lowercase and split them into an array called Word.

2. for every word, I make the first letter capital and add the rest of the word and a space.

3. loop until every word has been through the process and print the result.

function titleCase(str) {
let word = str.toLowerCase().split(' ');
let result = '';
for (let i = 0; i < word.length; i++){
result += word[i][0].toUpperCase() + word[i].substring(1) + ' ';
}

return result;
}

titleCase("I'm a little tea pot");

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

Challenge: Basic Algorithm Scripting - Title Case a Sentence

It may seem that way, but I don’t think so.

I think the issue is connected to this part of your code:

1 Like

OH wow, so you mean my string has this tiny space at the end of the sentence so it didn’t accept my answer? Thank you, so much I will try to fix it now.

Yep, that’s what I’ve meant

function titleCase(str) {
let word = str.toLowerCase().split(’ ');
let result = ‘’;
for (let i = 0; i < word.length; i++){
result += word[i][0].toUpperCase() + word[i].substring(1) + ’ ';
}
return result.substring(0, result.length-1);
}

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

This is probably nowhere close to the best solution but that’s how I solved it.
Thank you so much for ur help. Next time I will be careful of this tiny space.

If you solved it you may wanna see my solution.
I’ve actually solved it just yesterday, we are pretty close curriculum-wise.
I used .map()

Also. If you are posting working solutions, consider to blur the code.

1 Like

Can you teach me how to blur the code, please? Thank you

Yeah.
Begin to create new post or edit existing one.

On the top panel(where is B, I, emojis etc) you need the rightmost button.
Click it, and there will be option ‘blur the spoiler’.

1 Like

You probably want to look up the join() method on the Array prototype.

1 Like

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