Tell us what’s happening:
This code works when I execute it in Visual Studio Code
Describe your issue in detail here.
Below is what I get when I submit it in FreeCodeCamp but it still says it’s wrong. I mean know I need to change the console.log to a return statement. I’m just using the console.log to actually see the output. It comes out perfect when I execute from VSC to a browser window. I’m confused.
// console output
I’m A Little Tea Pot
I’m A Little Tea Pot
I’m A Little Tea Pot
Short And Stout
Here Is My Handle Here Is My Spout
Your code so far
function titleCase(str) {
let newStr = str.toLowerCase()
.replace(/\S/, str[0].toUpperCase())
let arr = newStr.split(' ');
let str2 = '';
let str3 = '';
let finalString = '';
while (arr.length > 0) {
str2 = arr.shift(arr[0])
str3 = str2.replace(/^/, ' ')
finalString += str3.replace(str3[1], str3[1].toUpperCase());
}
console.log(finalString);
}
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/111.0.0.0 Safari/537.36
Challenge: Basic Algorithm Scripting - Title Case a Sentence
Link to the challenge:
