Official solution return error

This is the official solution for the challenge, The ERROR message i get is
"TypeError: newTitle[st].toLowerCase().replaceAt is not a function"


function titleCase(str) {
const newTitle = str.split(" ");
const updatedTitle = [];
for (var st in newTitle) {
  updatedTitle[st] = newTitle[st]
    .toLowerCase()
    .replaceAt(0, newTitle[st].charAt(0).toUpperCase());
}
return updatedTitle.join(" ");
}

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

Challenge: Title Case a Sentence

Link to the challenge:

That error message is correct. There is no “replaceAt” method in JS. You would have to define it yourself or import it from a library.

I see this is solution 1 in the hints. The explanation makes reference to " modifying the replaceAt function using prototype" but this code isn’t included in the solution. So unless it is provided by default during testing (which it doesn’t appear to be) then it won’t work, which is why you are getting this error.

Also, I don’t think these are considered “official” solutions. I believe they are just possible solutions contributed by members over the years. Perhaps something was different back when this solution was contributed and a replaceAt method was provided? Or perhaps there originally was additional code that defined a replaceAt method and it has been removed over time?

3 Likes

Also, I don’t think these are considered “official” solutions. I believe they are just possible solutions contributed by members over the years.

Yup.

1 Like

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