+ 2
Why this code is not making the "Russia's" first letter capital, please help :'( [unsolved]
6 Answers
+ 6
let small = list[i].charAt(0).toUpperCase() + list[i].substring(1).toLowerCase();
This works ...
+ 3
let small= list[i].toLowerCase();
small = small.charAt(0).toUpperCase() + small.slice(1);
+ 3
Assuming list[i] is "Russia"
let small = list[i].toLowerCase();
<small> = "russia"
let first=list[i].slice(0,1);
<first> = "R"
small = small.replace(first, first.toUpperCase());
Remember <first> = "R",
Replace all <first> in <small> by <first>.toUpperCase()
But <small> doesn't have 'R' in it, <small> = "russia", it has 'r' as first letter, so the replace() did nothing cause it didn't find any 'R' in <small>.
+ 2
Ipang thanks, I did a little tweak to my code, instead for "let first=list[i].slice(0,1);" I did "let first=small.slice(0,1);"
+ 2
Anjali,
No problem ...
Nice one š