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 Antworten
+ 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