I'm trying to detect which word is a name, and capitalize the first letter of it. Here's the code I've tried:
else if (splitInput[i].match(/a|e|i|o|u/)){
i = 0;
var up = input.indexOf("ben");
up = up + 4;
console.log("toUpperCase: " + up);
i = slotBen + 1;
var toUp = input.charAt(up);
console.log("Before uppercase: " + toUp);
var afUp = toUp.toUpperCase();
//input.charAt(up).replace(toUp, afUp);
console.log("After toUpperCase: " + afUp);
//input.replace(toUp, afUp);
console.log(input);
bubbleR.innerHTML = input;
console.log('slotBen:', slotBen);
userID.name = splitInput[i];
Maybe a little too complex, but I couldn't make it work or easier to read/understand. If you run the function, it knows exactly which letter it has to capitalize, but it doesn't replace it in input
. Here's a codepen
Text is in Dutch, but don't mind that :)
Edit: had the suggestion to try this:
var capitalized = splitInput[i].toUpperCase() + input.substr(1);
with i being i = slotBen + 1;
, but it didn't work. I think I did implement it right, but I'm not sure. Tried different combinations and none worked out.