0
Iām having trouble adding another name to return
function fullName(firstName, lastName) { var firstName = "Clark"; var lastName = " Kent"; res = firstName + "" + lastName; return res; } fullName(); // Iām also suppose to add another name āJonah Hexā how can I add the 2nd name without messing up my code
8 Answers
+ 3
ES6 way: (might not work for old phone)
function fullName(firstName = "Clark", lastName = "Kent") {
res = firstName + " " + lastName;
return res;
}
alert(fullName());
var jonahFullnane = fullName("Jonah", "Hex");
alert(jonahFullnane);
https://code.sololearn.com/WFBcaL8a6ovC/?ref=app
+ 3
for non-ES6, old JavaScript way (work on old phone)
function fullName(firstName, lastName) {
this.firstName = firstName? firstName: "Clark";
this.lastName = lastName? lastName: "Kent";
this.res = this.firstName + " " + this.lastName;
return this.res;
}
alert(fullName());
var jonahFullnane = fullName("Jonah", "Hex");
alert(jonahFullnane);
https://code.sololearn.com/W74Ee0Uguc0L/?ref=app
+ 2
Try:
function fullName(firstName, lastName){
return firstName + ' ' + lastName;
}
// your code under here
function fullNameAndAge(firstName, lastName, age) {
return fullName(firstName, lastName) + ", " + age;
}
fullNameAndAge("Jonah", "Hex", 46);
+ 1
you can use arrays to store multiple first and last names
+ 1
CalviÕ² wow thanx a million man. your a whizā¼ļø
0
Daniel how can i do that with function fullName(firstName, lastName) {
var firstName = "Clark";
var lastName = " Kent";
res = firstName + "" + lastName;
return res;
}
\\ to add Jonah Hex
0
CalviÕ² thanx a bunch man tried solving this one but its sayin my syntax is have too many errors. but i dont see an error alert ..
https://foundations.nycda.tools/challenges/required-exercise-functions-part-3
0
CalviÕ²
//this is what i had
function fullNameAndAge(person) {
person = {
firstName: 'Jonah',
lastName: 'Hex',
age: '46'
};
return person;
}
https://foundations.nycda.tools/challenges/required-exercise-functions-part-3