Question 5
Consider the following code snippet.
const response = { meta: () => Promise.resolve([ { id: 1, score: 20 }, { id: 2, score: 40 }, ]), json: () => Promise.resolve([ { name: "Alpha", score: 40 }, { name: "Beta", score: 30 }, { name: "Charlie", score: 50 }, { name: "Delta" }, // no score ]),};
fetchData();
function fetchData() { Promise.resolve(response) .then((res) => res.json()) .then((data) => { const total = data .map((p) => parseInt(p.score) || 0) .filter((score) => score >= 40) .reduce((acc, score) => acc + score, 0); console.log("Total Score:", total); });}What will be logged to the console?
Total Score: 80
Total Score: 90
Total Score: 120
Total Score: NaN