Hello everybody
I didn’t understand how the slice() method is being used here (code pasted below).
let firstLetter = lower.slice(0,1);
I thought these index would refer to the first and second cities in the array, ‘lonDon’ and ‘ManCHESTer’, respectively. Instead, it is taking the first letter of each word. I am sure I am missing something, but I couldn’t figure it out on my own. I did some research and find nothing about it.
I’d appreciate if someone could enlighten me.
Thank you!
const list = document.querySelector(’.output ul’);
list.innerHTML = ‘’;
let cities = [‘lonDon’, ‘ManCHESTer’, ‘BiRmiNGHAM’, ‘liVERpoOL’];
for (let i = 0; i < cities.length; i++) {
let input = cities[i];
// write your code just below here
let lower = input.toLowerCase();
let firstLetter = lower.slice(0,1);
let capitalize = lower.replace(firstLetter, firstLetter.toUpperCase());
let result = capitalize;
let listItem = document.createElement(‘li’);
listItem.textContent = result;
list.appendChild(listItem);
}