Why this code is not making the "Russia's" first letter capital, please help :'( [unsolved] | Sololearn: Learn to code for FREE!
+ 2

Why this code is not making the "Russia's" first letter capital, please help :'( [unsolved]

https://code.sololearn.com/WpPY5Af0J3uw/?ref=app

29th Dec 2021, 5:21 AM
Samaan Sayed
6 Answers
+ 6
let small = list[i].charAt(0).toUpperCase() + list[i].substring(1).toLowerCase(); This works ...
29th Dec 2021, 5:43 AM
Ipang
+ 4
SoloProg Ipang thank you, but can you please explain me why my code was not working
29th Dec 2021, 5:45 AM
Samaan Sayed
+ 3
let small= list[i].toLowerCase(); small = small.charAt(0).toUpperCase() + small.slice(1);
29th Dec 2021, 5:42 AM
SoloProg
SoloProg - avatar
+ 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>.
29th Dec 2021, 6:02 AM
Ipang
+ 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);"
29th Dec 2021, 6:10 AM
Samaan Sayed
+ 2
Anjali, No problem ... Nice one 👍
29th Dec 2021, 6:15 AM
Ipang