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
23 changes: 23 additions & 0 deletions data/grades.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
let grades = [{
assignmentName: 'Array Reverser',
studentName: 'Nick',
score: 95
}, {
assignmentName: 'Number Summer',
studentName: 'Jessica',
score: 100
}, {
assignmentName: 'Area Finder',
studentName: 'Nick',
score: 100
}, {
assignmentName: 'Week04',
studentName: 'Nick',
score: 99
}, {
assignmentName: 'Week05',
studentName: 'Jessica',
score: 98
}]

module.exports = { grades }
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
- Use 2 distinct student names

*/

let { grades } = require('./data/grades')
// console.log(grades)
/**

Looping using your preferred looping syntax and updating a shared variable
Expand All @@ -38,9 +39,12 @@
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 +54,7 @@
Replace `null` below with the use of `reduce`

*/
gradeTotal = null
gradeTotal = grades.reduce((acc, grade) => {
return acc + grade.score
}, 0)
console.log(gradeTotal)