I have the following code:
function accum(s) {
let resultado = "";
let cadenaAgregar = "";
s.split("").forEach((item, i) => {
cadenaAgregar += item.repeat(i + 1);
cadenaAgregar[0].toUpperCase();
resultado += cadenaAgregar;
cadenaAgregar = "";
});
return resultado;
}
console.log(accum("abcd"));
Before the string is added to the 'result' variable the first letter is supposed to be converted to uppercase but this doesn't work, I'd appreciate knowing why this is happening and what I should do
Good day,
In the line where you want to change the first letter to uppercase you don't assign it to anything
So it's like it doesn't exist.
You can assign the conversion to the same variable
cadenaAgregar
:But that would remove the rest of the string, to include it you can use
String.prototype.slice()
Another option would be to use
charAt()
withslice()
Full example:
This returns: