This is my first forum post so I apologize in advance as I’m sure I’m very unfamiliar with posting on forums (I’m an introvert). I came up with a solution to the Title Case function and it isn’t working, although I don’t understand why. I wanted to ask in the forums why it isn’t working so that I could avoid making the same mistakes in the future. Here is the code.
function titleCase(str) {
let splitStr = str.split(' ');
let finishedWord = '';
for (let i = 0; i < splitStr.length; i++) {
let space = ' ';
let firstLetterOfWord = splitStr[i].charAt(0).toUpperCase();
let restOfWord = splitStr[i].substr(1).toLowerCase();
finishedWord += firstLetterOfWord;
finishedWord += restOfWord;
finishedWord += space;
}
return finishedWord ;
}
titleCase("I'm a little tea pot");
upon console.log(), everything checks out but it still says it isn’t passing tests. Does anyone know if I’m supposed to use a specific method to make it pass? Thanks in advance!!!
Thank you so much, RandellDawson!! I should have known something like that would creep up with the hackneyed solution I came up with, haha! I am going to research other ways to do it that have less issues. Thanks so much for your time!
Yup, when I ran it, it placed the *'s in the front and end where the spaces were. I worded what I meant to ask you wrong though, I meant does the * have any special function or is it showing that I have spaces present that need to be removed? I.E. is this the only way to check for extra spaces or could the same be achieved with any random value, as long as I’m console logging it that way?
Ah thanks so much, Jeremy, especially for the quick answering! I see the value in using the console log like you showed me! I will apply it going forward to double check things like this. It really is easy to mess up values if you don’t check them!