Title Case a Sentence w/ nonfunctional .join

Title Case a Sentence w/ nonfunctional .join
0

#1

Tell us what’s happening:
It is saying that str[i].join is not a function?
What is the deal?

Your code so far


function titleCase(str) {
  str.toLowerCase();
  str.split(" ");
  for(var i=0; i<str.length; i++) {
    str[i].split("");
    str[i][0].toUpperCase();
    str[i].join("");
    str.join(" ");
  }
  return str;
}

titleCase("I'm a little tea pot");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 OPR/50.0.2762.67.

Link to the challenge:


#2

Your code is not doing what you think it is doing. For example, str.toLowerCase(); does nothing to str, because you to not assign the result of it to anything. str.split(" “) does nothing, because you do not assign the result to anything. The same thing goes for str[i].split(”"); and str[i][0].toUpperCase();

When you finally get to str[i] in the first iteration of the for loop, i = 0, so str[0] is ‘I’ which is a string, and the join function does not work for strings. It works with arrays to create a string.

All of the functions you were using have a return value, but if you do not assign the value to a variable, then nothing really happens or at least nothing happens to str.

Take a look at the documentation for each of the functions toLowerCase, split, toUpperCase, and join and read about their return values.