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

1st Oct 2018, 12:31 AM
Junie B.
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
1st Oct 2018, 2:03 AM
CalviÕ²
CalviÕ² - avatar
+ 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
1st Oct 2018, 2:12 AM
CalviÕ²
CalviÕ² - avatar
+ 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);
1st Oct 2018, 3:51 AM
CalviÕ²
CalviÕ² - avatar
+ 1
you can use arrays to store multiple first and last names
1st Oct 2018, 1:22 AM
Daniel
Daniel - avatar
+ 1
CalviÕ² wow thanx a million man. your a whizā€¼ļø
1st Oct 2018, 3:57 AM
Junie B.
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
1st Oct 2018, 1:30 AM
Junie B.
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
1st Oct 2018, 3:17 AM
Junie B.
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
1st Oct 2018, 3:46 AM
Junie B.