-1

I want the first character of the string to be uppercase and the rest lowercase this is what I code

let title = prompt().toLowerCase();
for (let c of title)
{
    c[0]=c[0].toUpperCase();
}
nesnes
  • 1
  • 2

1 Answers1

0
  • There are many methods, and the following is just one of them.
    function toUpperCaseFirstLetter(str) {
      if (typeof str !== 'string' || str.length === 0) {
        return str;
      }

      return str[0].toUpperCase() + str.slice(1).toLowerCase();
    }

    // some tests
    expect(toUpperCaseFirstLetter('abc')).eql('Abc');
    expect(toUpperCaseFirstLetter('ABC')).eql('Abc');
    expect(toUpperCaseFirstLetter('')).eql('');
    // other tests....
skypesky
  • 1
  • 1