skip to Main Content

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


  1. that works correctly, you should write "const" correctly in the naming of the function.

    Login or Signup to reply.
  2. To capitalize the first letter of a passenger’s name in JavaScript, you can use the following function:

    const capitalizePassengerName = function (name) {
      const passengerName = name.toLowerCase();
      const passengerCorrectName =
        passengerName.charAt(0).toUpperCase() + passengerName.slice(1);
      console.log(passengerCorrectName);
    };
    
    capitalizePassengerName("fAdi"); // Output: Fadi
    

    In this function, we first convert the entire passenger name to lowercase using toLowerCase(). Then, we capitalize the first letter using charAt(0).toUpperCase() and concatenate it with the rest of the lowercase name using slice(1). This will correctly capitalize the name, resulting in "Fadi" as the output.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search