diff --git a/data.js/grades.js b/data.js/grades.js new file mode 100644 index 0000000..8abd6c5 --- /dev/null +++ b/data.js/grades.js @@ -0,0 +1,25 @@ +const grades = [{ + assignmentName: 'calculator', + studentName: 'kevin', + score: 65 +}, { + assignmentName: 'fantasy', + studentName: 'lisa', + score: 78 +}, { + assignmentName: 'hazy', + studentName: 'kevin', + score: 90 +}, { + assignmentName: 'challenge', + studentName: 'lisa', + score: 82 +}, { + assignmentName: 'perfect', + studentName: 'lisa', + score: 96 +}] + +module.exports = { + grades +} \ No newline at end of file diff --git a/index.js b/index.js index 856a122..388a2d5 100644 --- a/index.js +++ b/index.js @@ -29,6 +29,9 @@ - Use 2 distinct student names */ +const { grades } = require("./data.js/grades") + +console.log( {grades} ) /** @@ -38,9 +41,18 @@ Update `gradeTotal` so it increases value for each item in the array */ - const gradeTotal = 0 +// expect gradeTotal = 411 + + let gradeTotal = 0 + + for (let i = 0; i < grades.length; i++) { + gradeTotal += grades[i].score + } + console.log( {gradeTotal} ) + + /** Using reduce @@ -50,4 +62,9 @@ Replace `null` below with the use of `reduce` */ - gradeTotal = null + gradeTotal = grades.reduce( (total, grade) => { + console.log(total, grade) + return total + grade.score + }, 0 ) + + console.log(gradeTotal)