Quantcast
Channel: freeCodeCamp Challenge Guide: Title Case a Sentence
Viewing all articles
Browse latest Browse all 50

freeCodeCamp Challenge Guide: Title Case a Sentence

$
0
0

Same here! I wrote the following code which seems to give all the desired outputs, yet I only get a checkmark for the first criteria but a red X for the other three.

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

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

EDIT: Of course, I realized my error right after I posted. I changed the final return line to:

return arr2.slice(0, -1)`

Read full topic


Viewing all articles
Browse latest Browse all 50