What am i getting wrong?
Add a method to the Person's prototype called "getInitials" that returns the first letter of their first and last name, both capitalized.
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
person.prototype.getInitials = function (person){
var names = person.split(' '),
initials = names[0].substring(0, 1).toUpperCase();
if (names.length > 1) {
initials += names[names.length - 1].substring(0, 1).toUpperCase();
}
console.log(initials);
}
/ Do not modify code below this line /
const johnDoe = new Person('john', 'doe');
console.log(johnDoe.getInitials(), '<-- should be "JD"');
It seems like you have several errors that you need to fix. Let's start from the top going down.
Line 5: You said
person
. However, that refers to a variable. You need to capitalize it to get the object:Person.prototype...
.Line 5: The function
getInitials
should not take any parameters. Change the initialization tofunction () {...
return
statement instead.That should be perfect!
If this answers your question, please check the checkmark on the left side of this message. Thanks and Good Luck!
@vedprad1 thank you so much. This was really helpful
@ayormeday : Great! Could you please mark my answer as correct? Thanks!
@vedprad1 is there anyway I can keep in touch with you on further problems?
@ayormeday : If you have other questions, you can post them here, at repl.it's ask page. You can also post it at my ask page: https://tinyurl.com/coders-ask
@vedprad1 Can you help me with a problem ?
@MIAlien : You should post it in another post, because it is a different question.
What kind of return statement was supposed to be returned [email protected]
@XaverPinero : I have never heard of kinds of return statements. All you have to do is
return initials;
.