Link to home
Start Free TrialLog in
Avatar of Temir Aliev
Temir AlievFlag for United States of America

asked on

Having issues with array methods

/*
Instructions

Take a look at the myName object. Replace "YOURFIRSTNAME" and "YOURLASTNAME" so it contains your first name and your last name.
We also have provided a makeName function for you that will take a first name and last name and combine them.
Create a variable called firstLast to hold the result of mapping over myName and returning your first and last name using makeName.

Hint
Use dot notation to access the first and last name values.
*/

//GIVEN TASK:

var myName = [{first:"YOURFIRSTNAME", last:"YOURLASTNAME"}]

function makeName(firstName, lastName){
  return firstName + " " + lastName;
}

//code here

Open in new window




// MY SOLUTION IS:

var myName = [{first:"Sean", last:"Thompson"}]

function makeName(firstName, lastName){
  return firstName + " " + lastName;
}

var firstLast = makeName(myName);
console.log(firstLast);

Open in new window




//WHAT IS WRONG HERE?
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

try:

var firstLast = makeName(myName[0].first, myName[0].last);

Open in new window

Please try tested function.

var myName = [{first:"Sean", last:"Thompson"}]

function makeName(nameObj)
{
  return nameObj.first + " " + nameObj.last;
}

var firstLast = makeName(myName[0]);
document.write(firstLast);

Open in new window


OUTPUT
Sean Thompson

Open in new window

Avatar of Temir Aliev

ASKER

Thanks Pawan Kumar,
Your code worked perfectly fine, but the school platform where I am being tested on is not accepting this solution since it is not following the instructions defined above in the description. Ryan's version i think met all the requirements and yours definitely solves the problem but I guess it is a bug on the platform which is why it is not accepting the answer.
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I disagree with the allocation. The author already stated that the proposed solution
https://www.experts-exchange.com/questions/29070127/Having-issues-with-array-methods.html?anchorAnswerId=42380104#a42380104
and
https://www.experts-exchange.com/questions/29070127/Having-issues-with-array-methods.html?anchorAnswerId=42380067#a42380067
Did not pass muster on the school platform.

This is because they were not correct in terms of the requirement of the teaching example. The reason being that the teaching example was teaching how to use mapping of arrays - which neither of the above solutions dealt with.

This solution https://www.experts-exchange.com/questions/29070127/Having-issues-with-array-methods.html?anchorAnswerId=42381392#a42381392 is the only one that deals with the issue of mapping.

While the other two samples produced the correct output - that was not the point of the teaching exercise. In a teaching example you get the solution correct not only when you achieve the right answer but also the right method - the right method here was to use the map function.
Thanks Pawan Kumar,
Your code worked perfectly fine, but the school platform where I am being tested on is not accepting this solution since it is not following the instructions defined above in the description. Ryan's version i think met all the requirements and yours definitely solves the problem but I guess it is a bug on the platform which is why it is not accepting the answer.

We need the response from asker, if it's not, then I would suggest to delete this question.
Sorry I totally forgot to close this question, Julians answer was accepted by the  platform, I dont really understand how this awesome website's point system works, seems like there is a discussion over whose solution was most helpful. You guys all helped me understand the concept even if not all the provided solutions were accepted, at least now I know why certain solutions work in different cases. Thank you all, I am extremely sorry for not ,closing it in a timely manner.
Dear Temir,

Going forward please mention about your testing platform in the requirement itself.
@Pawan,
Please refer the author's comment
Thanks Pawan Kumar,
Your code worked perfectly fine, but the school platform where I am being tested on is not accepting this
@Julian,
This we got after submitting the comment. This was not mentioned in the original question.