Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions data/grades.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

const grades = [{
assignmentName: 'Assignment 1',
studentName: 'Nicholas',
score: 75
}, {
assignmentName: 'Assignment 1',
studentName: 'Michael',
score: 80
}, {
assignmentName: 'Assignment 2',
studentName: 'Nicholas',
score: 90
}, {
assignmentName: 'Assignment 2',
studentName: 'Michael',
score: 100
}, {
assignmentName: 'Assignment 3',
studentName: 'Nicholas',
score: 85
}, {
assignmentName: 'Assignment 3',
studentName: 'Michael',
score: 65
}]

module.exports = {
grades
}
28 changes: 24 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,25 @@

*/

const { grades } = require('./data/grades')



/**



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
grades.forEach( (grade) => {
gradeTotal += grade.score
})
console.log( {gradeTotal} )
/**

Using reduce
Expand All @@ -50,4 +58,16 @@
Replace `null` below with the use of `reduce`

*/
gradeTotal = null

// function totalGrade(grades) {
// return grades.reduce((acc, grade) => { return acc = acc + grade.score }, 0)
// }
//

gradeTotal = grades.reduce( (total, grade) => {
console.log(total)
return total + grade.score

}, 0 )

console.log ({gradeTotal})