Now, in the getGrades variable, we're going to get the schoolId that we're using to look things up with. Then we're going to go ahead and return a new promise; this is all part of the contrived example, resolve and reject are our two arguments:
const getGrades = (schoolId) => {
return new Promise((resolve, reject) => {
});
};
Then, right here, we're going to go ahead and resolve the filtered grades array, that is grades.filter. We're going to filter this one by passing an arrow function. It'll get called with the individual grade, not user, and then we'll go ahead and implicitly return something. If we return true, it'll be considered a match and that grade will be resolved. If we return false, that grade will be removed from the array that gets resolved. In this case, we want to keep the grade if the grade.schoolId equals the schoolId that the function was called with.
const getGrades = (schoolId) => {
return new Promise((resolve, reject) => {
resolve(grades.filter((grade) => grade.schoolId === schoolId));
});
};
In this case, that is it for getGrades; we can go ahead and test it out. I'm going to call getGrades instead of getUser. I'm going to pass in a valid schoolId like 101 and, instead of user, we'll have grades and next:
getGrades(101).then((grades) => {
console.log(grades);
}).catch((e) => {
console.log(e);
});
If I save this, what do we get? We get an array with two objects, as expected:

We have all the grades for Andrew, 86 and 80. I'm going to go ahead and pass in 999; we get Jessica's grades and, finally, we pass in 12:
getGrades(12).then((grades) => {
console.log(grades);
}).catch((e) => {
console.log(e);
});
If I pass in 12, we get an empty array, which is exactly what I was hoping for. Just one more function left, and then we'll be done with this section and we can move on to the next one.