Javascript function that receives a string and adds space before every capital letter [closed]

I wasn’t successful in creating a function as such that works properly.

I was trying to use “if” and “for” inside the function.

The function must return the string with the added spaces before every capital letter.

Would love to receive some help, Thanks.