Title Case a Sentence- white-space

Title Case a Sentence- white-space
0

#1

Tell us what’s happening:

i am through with the problem but i want to insert white space in between the output not including the last part something like this I_Am_Happy where “_” is the white space and not I_am_happy

Your code so far


function titleCase(str) {
  let arr = str.split(" ")
  let upper = ""
  let complete =""
  for (var i = 0; i < arr.length; i++) {
     upper = arr[i][0].toUpperCase() + arr[i].slice(1);
    
    complete += " " + {upper};
    
  }
  console.log(complete);
  return complete;
}

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/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/title-case-a-sentence/


#2

I am confused about your question. I assume you understand the code you have above does not pass the tests and it seems you want the code above to do something different?
You said you want the code to output “I am happy”? So you only want to capitalize the first word of the sentence and all the other words to just be the same as in str?

If so, then you could write:

function capFirstWord(str) {
  return str[0].toUpperCase() + str.slice(1);
}

#3

i want the code to output I_A_Happy and not I_am_Happy where "" represent white space that is each word of the string must be capitalised with white space between them i have achieved this but their is a white space at end like I_Am_Happy