Basic Algorithm Scripting - Title Case a Sentence

My solution worked when I console.log the return value, so why does it fail the tests?

Your code so far

function titleCase(str) {
  let strArray = str.split(" ");
  let newStr = ""

  for (let i = 0; i < strArray.length; i++) {
    strArray[i] = strArray[i].toLowerCase();
    newStr += strArray[i].slice(0, 1).toUpperCase();
    newStr += strArray[i].substring(1) + " ";
  return newStr;

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:108.0) Gecko/20100101 Firefox/108.0

Challenge: Basic Algorithm Scripting - Title Case a Sentence

Link to the challenge:

Double check the output. You have an extra character in your result at the end.

Oh, the extra white space. That makes sense. Thank you.

1 Like

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