我试图编写代码,使名字和姓氏的首字母大写,其余字母小写,还使用 split 和 join 进行间距。
let [firstName, lastName]=prompt("What is your name?").split(" ");
firstName=firstName.toUpperCase(firstName).slice(0,1);
lastName=lastName.toUpperCase(lastName).slice(0,1);
firstName=firstName.toLowerCase(firstName).slice(1,firstName.length);
lastName=lastName.toLowerCase(lastName).slice(1,lastName.length);
const newName=[firstName,lastName].join(" ");
console.log(newName);
显示的是“amnik idhu”而不是“Ramnik Sidhu”