diff --git a/data.js b/data.js new file mode 100644 index 0000000..530b716 --- /dev/null +++ b/data.js @@ -0,0 +1 @@ +module.exports = grades \ No newline at end of file diff --git a/index.js b/index.js index 856a122..de78a4b 100644 --- a/index.js +++ b/index.js @@ -29,19 +29,40 @@ - Use 2 distinct student names */ +let grades =[{assignmentName: "week01", studentName: "James", score: 10}, + {assignmentName: "week02", studentName: "paul", score: 20}, + {assignmentName: "week03", studentName: "James", score: 30} +, {assignmentName: "week04", studentName: "Mathieu", score:40}, + {assignmentName: "week05", studentName: "paul", score: 50}] + +//console.log({grade}) + + //let { grades } = require(`./data/grades`) - /** - + /** +co Looping using your preferred looping syntax and updating a shared variable 2) Loop through the grades data using a for loop. Update `gradeTotal` so it increases value for each item in the array */ - const gradeTotal = 0 - + let gradeTotal = 0 + + for (let i= 0; i < grades.length; i++ ) { + + + gradeTotal += grades[i].score + } + console.log({gradeTotal}) + gradeTotal = grades.reduce( (total, grade)=> { + console.log(total, grade) + return total + }, 0) /** + * + * Using reduce