diff --git a/data/grades.js b/data/grades.js new file mode 100644 index 0000000..3140e21 --- /dev/null +++ b/data/grades.js @@ -0,0 +1,30 @@ +let grades = [ + { + assignmentName: 'Assignment 01', + studentName: 'Tito', + score: 85, + }, + { + assignmentName: 'Assignment 02', + studentName: 'Ralph', + score: 74, + }, + { + assignmentName: 'Assignment 03', + studentName: 'Ralph', + score: 90, + }, + { + assignmentName: 'Assignment 03', + studentName: 'Tito', + score: 95, + }, + { + assignmentName: 'Assignment 04', + studentName: 'Ralph', + score: 85, + }, +] +module.exports = { + grades +} \ No newline at end of file diff --git a/index.js b/index.js index 856a122..c92ea9c 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,8 @@ - Use 2 distinct student names */ - +const { grades } = require('./data/grades') +console.log({grades}) /** Looping using your preferred looping syntax and updating a shared variable @@ -38,9 +39,16 @@ Update `gradeTotal` so it increases value for each item in the array */ - const gradeTotal = 0 +let gradeTotal = 0 + +for (const index in grades) { + const grade = grades[index] + gradeTotal += grade.score +} +//expect gradeTotal = 429 +console.log({gradeTotal}) /** Using reduce @@ -50,4 +58,15 @@ Replace `null` below with the use of `reduce` */ - gradeTotal = null + +let titosGrades = grades.filter((grade) => { + return grade.studentName === 'Tito' +}) +console.log({titosGrades}) + + titosTotal = titosGrades.reduce((total, grade) => { + console.log(total, grade) + return total + grade.score + }, 0) + +console.log(titosTotal) \ No newline at end of file