Hey guys, I have a question.
I have found a solution and I would like to work it through.
How can I add my variable replacer all at once instead of once every iteration?
Thanks.
**Your code so far**
function spinalCase(str) {
const regex = /\s/g
console.log(str);
for (let i = 0; i < str.length; i++) {
const addMe = '-'
if (str[i].toUpperCase() === str[i]) {
const replacer = addMe + str[i];
console.log(str.replace(str[i], replacer).toLowerCase());
}
}
}
spinalCase("thisIsSpinalTap");
/* loop over str
if there an upperCase letter
replace letter with a '-' and a smaller case letter or add '-' before the letter and then lowerCase string.
if there isn't replace spaces with '-'.
*/
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36
Because it is not quite there yet so I don’t want to return, I console.log.
I have the issue that I asked the question about, I believe if I solve it I should continue and I will pass the challenge, but I am not sure how to figure out the question I asked, so I have come here.