question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'Title Case a Sentence' challenge not accepting results

See original GitHub issue

Challenge Name

Title Case a Sentence

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

screenshot

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
deni86commented, Feb 5, 2017

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.

capitalize= array.join(" ");  

} return capitalize; }

titleCase(“I’m a little tea pot”);

1reaction
DIZAD87commented, Jan 16, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found