I need help with this. I am getting an error and don’t understand why.
Here is the question
"This is an extension of question #2. Given an array of objects, write a function admin that returns the name and birthdate of all users that are marked as “admin”. "
below is the error
-Failed tests
handle_given_input
ReferenceError: admin is not defined
handle_additional_input
ReferenceError: admin is not defined
Below is my code
// Write your admin function here
const users = [
{
name: 'Homer',
role: 'clerk',
dob: '12/02/1988',
admin: false
},
{
name: 'Lisa',
role: 'staff',
dob: '01/30/1965',
admin: false
},
{
name: 'Marge',
role: 'associate',
dob: '09/10/1980',
admin: true
}
]
function namesAndRoles(users) {
input = '';
for(let key of users) {
if ( key['admin'] === true){
Name = "Name: " + key.name
Dob = "\nDob: " + key.dob
input += Name + Dob + "\n\n"
}
}
return input;
}
output = namesAndRoles(users);
console.log(output);
// Name: Marge
// Dob: 09/10/1980
Here is question #2
Given an array of users, write a function, namesAndRoles that returns all of user’s names and roles in a string with each value labeled.
Question #3 is the original post
This is an extension of question #2. Given an array of objects, write a function admin that returns the name and birthdate of all users that are marked as “admin”.
No, question #2 just wants the names and roles from the array-object which my code passed fine.
In question number #3 is where I took the code from my answer in #2 an added an if statement so it would only return the admin that were true.
Of course change Role to Dob as well
Try clearing your browser cache and if it still doesn’t work, try running it on an incognito mode. Can you maybe give us a screenshot of the error occuring
Hello there, @kojicephas
If you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.
Occams Razor- The simple answer is most likely the correct one.
After sleeping on this I realized
I forgot to change the function namesAndRoles (users) in my 2nd challenge question to function admin(users) for my 3rd challenge question.
Thank you for helping me realize the answer remains in front of us usually.