You cannot mutate strings directly as you are trying - you have to create a new string by concatenating the pieces you want:
document.getElementById('namePlaceholder').innerHTML =
name.value.charAt(0).toUpperCase() + // will give you "J"
name.value.slice(1).toLowerCase() + // will give you "ames"
' is here ';
In lay terms, the slice(1)
part says "grab everything after the first character". In more technical terms, if you have the name James, you can think of it as a series of letters (not an array, but kinda):
['J', 'a', 'm', 'e', 's']
.
You can access individual letters like name[0]
, which will give you "J" and name[3]
which will give you "e". You can then do name.slice(1)
, which will start at "a" and grab everything after it: "ames". To illustrate further, you could do name.slice(-2)
to get the last 2 characters: "es". Or, if you want "me", you can do name.slice(2, 4)
.