// If given "George", "Washington" as arguments, it should return "Washington, George"
function formatName(firstName, lastName) {
return [lastName, firstName];
}
请参阅链接。我无法弄清楚如何在名字和姓氏之间加上一个简单的空格。我一直在这个几个小时请帮忙!在javascript中添加空格?
// If given "George", "Washington" as arguments, it should return "Washington, George"
function formatName(firstName, lastName) {
return [lastName, firstName];
}
请参阅链接。我无法弄清楚如何在名字和姓氏之间加上一个简单的空格。我一直在这个几个小时请帮忙!在javascript中添加空格?
使用字符串连接
return lastName +', '+ firstName;
function formatName(firstName, lastName) {
return lastName +', '+ firstName;
}
console.log(formatName("George","Washington"))
,如果你的任务是真正处理给定数组不是使用Array.prototype.join()
method与所需分离参数', '
function formatName(firstName, lastName) {
return [lastName, firstName].join(', ');
}
console.log(formatName("George","Washington"))
您应该返回串接的姓和名的字符串。试试这个:
return lastName +", "+ firstName;
这个工作。感谢您的帮助,我知道这很简单! – ATLcodemaster
我很抱歉,为什么会有人倒退我的答案? –
尝试join(', ')
function formatName(firstName, lastName) {
return [lastName, firstName].join(', ');
}
发布您的代码作为文本而不是图像。你在这个“数小时”的努力中尝试了什么? –
你可以做'return $ {firstName} $ {lastName}' –