After you’ve found the word to replace, check first if the first letter is uppercase. If so, you should also uppercase the first letter of the replacement word.
You may want to check out
.charCodeAt() or regex to test if a letter is uppercase.
EDIT. Please copy and paste your code in the future instead of posting a screenshot, so others can copy and paste your code as well (instead of typing everything).