I’m struggling with this exercise:
Given is a string n. The task is to return the sentence in CamelCase notation. This means that each new word is capitalized and immediately appended to the old word. Start with a lowercase letter.
I’ve tried this:
function camelCase(s) {
let result = "";
// Convert the first character to lowercase
result += s[0].toLowerCase();
for (let i = 1; i < s.length; i++) {
// Check for spaces and capitalize the next character
if (s[i] === ' ') {
result += s[i + 1].toUpperCase();
i++; // Skip the space character
} else {
result += s[i];
}
}
return result;
}
but get this error: https://i.stack.imgur.com/duZVr.png
New contributor