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();
}
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();
}
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....