This simple program I am making, solution, isn't returning the intended output.
If the string includes the phrase camelCasing the expected output should be camel Casing. If the string includes any other words like camelCasingCarrier the output should be camel Casing Carrier.
If the string includes any other phrase, it should just return the string.
function solution(string) {
let newString = null;
let stringToAdd = ' '
if (string.includes('camelCasing')) {
for (let i = 0; i < string.length; i++) {
let letter = string[i];
if (letter == letter.toUpperCase()) {
newString = string.substring(0, letter) + stringToAdd + string.substring(letter);
}
}
return newString;
} else {
return string;
}
}
My current output is camelCasingCarrier with a space at the beginning rather than the expected output. What is my issue and how should I fix this? Thanks again :)
newStringthat you made on the previous iteration.newString, not overwrite it completely.letteris a letter. Maybe you meant to usei?newString = ''then usenewString +=to add to it.