Basic Algorithm Scripting - Title Case a Sentence

Tell us what’s happening:
Describe your issue in detail here.
Although My Output Is Completely True, It Says That I’m Wrong

  **Your code so far**
function titleCase(str) {
str=str.split(" ")
let oneLine=""
let eachWord=[]
for(let i=0; i<str.length; i++){

for(let j=0; j<eachWord.length; j++){
  oneLine+=eachWord[j][0].toUpperCase()+((eachWord[j].replace(eachWord[j][0],"")).toLowerCase())+" "
  //oneLine+=(array[j][0].toUpperCase())+(array[j].toLowerCase()).replace(array[j][0],"")+" "

return oneLine;

console.log(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT"));
  **Your browser information:**

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

Challenge: Basic Algorithm Scripting - Title Case a Sentence

Link to the challenge:

some issues are not easy to see.

In this case I would suggest you build your output like this so you can see it

console.log(`"${titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")}"`)


As you can see the output string is "Here Is My Handle Here Is My Spout " – it has an extra space

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