how to Capitalization the name and tha lastaname of passanger in javaScript ?
onst checkPassangerName = function (name) {
const passangerName = name.toLowerCase();
const passangerCorrectName =
passangerName[0].toUpperCase() + passangerName.slice(1);
console.log(passangerCorrectName);
};
checkPassangerName("fAdi");
2
Answers
that works correctly, you should write "const" correctly in the naming of the function.
To capitalize the first letter of a passenger’s name in JavaScript, you can use the following function:
In this function, we first convert the entire passenger name to lowercase using
toLowerCase()
. Then, we capitalize the first letter usingcharAt(0).toUpperCase()
and concatenate it with the rest of the lowercase name usingslice(1)
. This will correctly capitalize the name, resulting in "Fadi" as the output.