Currently tackling a Code Wars challenge where I need to create a string with alternating upper and lowercase letters, starting with an uppercase letter. Here's the link to the challenge.
This is the approach I've taken:
function toWeirdCase(string){
let newString = [];
for(let i in string ) {
if(i%2 == 0) {
newString.push(string[i].toUpperCase());
} else {
newString.push(string[i].toLowerCase());
}
}
return newString.join('');
}
I'm currently facing an issue with accounting for spaces and ensuring that each word starts with a capital letter.