Hi,
I’m unsure why my answer produces undefined + answer im looking for.
let array = string.toLowerCase().split(" ");
let word;
for (let i = 0; i < array.length; i++){
word += array[i].charAt(0).toUpperCase() + array[i].slice(1);
}
return word;
}
console.log(camelize("Javascript is great"))
Whereas this produces the correct answer:
function camelize (string){
let array = string.toLowerCase().split(" ");
let word;
for (let i = 0; i < array.length; i++){
array[i] = array[i].charAt(0).toUpperCase() + array[i].slice(1);
}
return array.join("");
}
console.log(camelize("Javascript is great"))
I have not really seen variable[i] = …
online variable += … where the result is continually added to the variable.
Please can someone explain why when you do this the first thing in the list is undefined.
Thank you for your help!