Basic Algorithm Scripting - Title Case a Sentence

The output is totally fine, but the test fails except the return string one.


function titleCase(str) {
  const strArr =str.split(" ")
  let strOut =""
  for (let ele of strArr){
      strOut +=`${ele[0].toUpperCase()}${ele.slice(1).toLowerCase()} `
  } 
  return strOut
}

console.log(titleCase("I'm a little tea pot"));
console.log(titleCase("sHoRt AnD sToUt"));


Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36

Challenge: Basic Algorithm Scripting - Title Case a Sentence

Link to the challenge:

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

my guess is you have an extra space at the end of the output string
I'm A Little Tea Pot <==

you can see that space if you replace your code to this:
strOut +=${ele[0].toUpperCase()}${ele.slice(1).toLowerCase()}=``

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