Temir Aliev
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:
// MY SOLUTION IS:
//WHAT IS WRONG HERE?
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
// MY SOLUTION IS:
var myName = [{first:"Sean", last:"Thompson"}]
function makeName(firstName, lastName){
return firstName + " " + lastName;
}
var firstLast = makeName(myName);
console.log(firstLast);
//WHAT IS WRONG HERE?
Please try tested function.
OUTPUT
var myName = [{first:"Sean", last:"Thompson"}]
function makeName(nameObj)
{
return nameObj.first + " " + nameObj.last;
}
var firstLast = makeName(myName[0]);
document.write(firstLast);
OUTPUT
Sean Thompson
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
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.
Going forward please mention about your testing platform in the requirement itself.
@Pawan,
Please refer the author's comment
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.
This we got after submitting the comment. This was not mentioned in the original question.
Open in new window