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,
I make every word lowercase and split them into an array called Word.
for every word, I make the first letter capital and add the rest of the word and a space.
loop until every word has been through the process and print the result.
Thank you for spending your time reading/helping me.
Your code so far
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");
**Your browser information:**
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
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.
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() Relevant thread
Also. If you are posting working solutions, consider to blur the code.