Title Case a Sentence (slice(1) problem)

Hello, I have just done “Title Case a Sentence” Algorithm with some help from forum, it works, but I’m still not sure how the “slice(1)” part is working.Could You explain? Thanks. Here’s my code:

function titleCase(str) {
  var editing = str.toLowerCase().split(" ");
  var newEditting = editing.map(function(val){
    return val.charAt(0).toUpperCase() + val.slice(1);
  var joined = newEditting.join(" ");
  return joined;

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

Slice can take up to two arguments, the first and second index of what you want to slice. If only one argument is given, as in this case, it will take the remainder of the string.

This way you get all the words, no matter their length!

on the string “Hello”, calling slice(1) would return “ello”

1 Like

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

1 Like