Basic algorithum scripting challenges - Title case sensitive

Basic algorithum scripting challenges - Title case sensitive
0.0 0

#1

Hi,

Could you help me please. My code is working in testing (I think!) but i am not passing my challenge. Its the Title Case a Sentence in basic algorithum scripting challenges. Any advise would be massively appreciated. This is my code:

function titleCase(str) {
  var array = [];
  array = str.toLowerCase(); 
    
  
  newArray = array.split(" ");  

  var answer ="";


    for(var i=0; i < newArray.length; i++ )   {  
    
        var caps = newArray[i].charAt(0).toUpperCase() + newArray[i].substr(1);
    
         var joined = Array.prototype.join.call(caps, "");
            
              answer = answer+joined+" ";
    }
    
      return answer;

}
titleCase("HERE IS MY HANDLE HERE IS MY SPOUT");

#2

Arrgghhh sorry i didn’t know how to post all my code properly on here :frowning:


#3

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#4

You are adding a space to the end of all your strings.


#5

Thank you so much!! :grinning: