What am i getting wrong?
ayormeday (10)

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();

/ Do not modify code below this line /

const johnDoe = new Person('john', 'doe');
console.log(johnDoe.getInitials(), '<-- should be "JD"');

You are viewing a single comment. View All
vedprad1 (844)

It seems like you have several errors that you need to fix. Let's start from the top going down.

  1. Line 5: You said person. However, that refers to a variable. You need to capitalize it to get the object: Person.prototype....

  2. Line 5: The function getInitials should not take any parameters. Change the initialization to function () {...

  3. Line 6 to Line 11: I do not really understand the things going on here. Mainly, you cannot use split on an object. I would replace this entire code with:
var initials = this.firstName.charAt(0).toUpperCase() + this.lastName.charAt(0).toUpperCase();
  1. Line 12: You are going to log the output later, so you don't need to log it now. Use a 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!

ayormeday (10)

@vedprad1 thank you so much. This was really helpful

vedprad1 (844)

@ayormeday : Great! Could you please mark my answer as correct? Thanks!

ayormeday (10)

@vedprad1 is there anyway I can keep in touch with you on further problems?

vedprad1 (844)

@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

MIAlien (1)

@vedprad1 Can you help me with a problem ?

vedprad1 (844)

@MIAlien : You should post it in another post, because it is a different question.

XaverPinero (0)

What kind of return statement was supposed to be returned [email protected]

vedprad1 (844)

@XaverPinero : I have never heard of kinds of return statements. All you have to do is return initials; .