fluorke,
function func(string) {
let position = -1;
do {
const before = string.substring(0, position + 1); //with space
const needle = string.substr(position + 1, 1);
const after = string.substring(position + 2);
string = before + needle.toUpperCase() + after;
} while ((position = string.indexOf(' ', position + 1)) >= 0);
return string;
};
alert(
func('вася петя маша таня')
);