'Title Case a Sentence' challenge not accepting results
See original GitHub issueChallenge Name
Issue Description
01/13/17 10:20A: My code for this challenge delivers the results of the test cases but for some reason its not letting me pass.
Browser Information
- Browser Name, Version: Chrome Version 55.0.2883.87 m
- Operating System: Windows 7
- Mobile, Desktop, or Tablet: Desktop
Your Code
function titleCase(str)
{
var wordSplit = str.toLowerCase().split(" "); //Change all characters to lower and split to new array
var wordUpper = []; //Initialize the new array
for(var i = 0; i < wordSplit.length; i++) // Scan through the words of the new array
{
wordUpper.push(wordSplit[i][0].toUpperCase()); //Capitalize the first letter
for(var j = 1; j < wordSplit[i].length; j++)
{
wordUpper.push(wordSplit[i][j]); //Push the remaining letters
}
wordUpper.push(" "); //Add a space after each word
}
return wordUpper.join(""); //Join all the words together
}
titleCase("I'm a little tea pot");
Screenshot
Issue Analytics
- State:
- Created 7 years ago
- Comments:5
Top Results From Across the Web
Solving "Title Case a Sentence" / freeCodeCamp Algorithm ...
My guide, notes, and solution to freeCodeCamp's basic algorithm challenge, "Title Case a Sentence". Tagged with freecodecamp, algorithms, ...
Read more >Free Code Camp challenge - Title Case A Sentence
I'm currently going through the First JS challenges of Free Code Camp. I'm having trouble with the challenge titled Title Case a Sentence....
Read more >Title case capitalization - APA Style
Lowercase only minor words that are three letters or fewer in a title or heading (except the first word in a title or...
Read more >Sentence-Case Versus Title-Case for Topic-Based Authoring
The issue of whether to use sentence-case or title-case for topic and section titles can be nearly as controversial and personal for us...
Read more >Title Case a Sentence - Basic Algorithm Scripting - YouTube
In this basic algorithm scripting tutorial we write an algorithm that title cases a sentence. This is another tutorial that makes up a ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi everyone… There is easier solution for ‘Title Case a Sentence’ with less of code:
function titleCase(str) { var array = str.toLowerCase().split(" ");//With split() you return an array of values and every word is now in lower case. var capitalize = [];
for(var i = 0; i<array.length; i++){ array[i] = array[i].charAt(0).toUpperCase() + array[i].substr(1);//First letter now is upper case and rest of the letters is added to first letter with array[i].substr(1) in which we remove first letter which is lower case.
} return capitalize; }
titleCase(“I’m a little tea pot”);
I figured out what I did wrong and decided to close my issue. I was adding a space after each word to help separate them and although it looks correct on the console, it wasn’t passing the system check because of that extra space on the end. To fix it, I "popped"out the last space of my string and it worked.