Basic Algorithm Scripting - Title Case a Sentence

Tell us what’s happening:
Hello everyone! I’ve been working on this challenge. This is my code so far. I don’t know what’s wrong with my code and why it won’t pass. Please help me. Thank you very much!

Your code so far

function titleCase(str) {
  let newStr = str.toLowerCase();
  newStr[0] = str[0].toUpperCase();
  for(i = 1; i < str.length; i++){
    if(str[i] === " "){
      newStr[i+1] = str[i+1].toUpperCase;
  return newStr;

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Basic Algorithm Scripting - Title Case a Sentence

Link to the challenge:

newStr[0] = str[0].toUpperCase();
newStr[i+1] = str[i+1].toUpperCase;

I don’t think you can do it like this. Immutable.

What is a String in JS? The JavaScript String Variable Explained.

1 Like

Thank you very much! Now I understand what my problem is.

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