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
1 change: 1 addition & 0 deletions data/grades.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const { grades } = require('./index.js')
61 changes: 46 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
Create a new file named "grades.js" to import in the data folder

Declare and initialize an array named `grades`

*/
const grades = [
{ assignmentName: 'Assignment 01', studentName: 'Ben', score: 50 },
{ assignmentName: 'Assignment 02', studentName: 'Jerry', score: 80 },
{ assignmentName: 'Assignment 02', studentName: 'Ben', score: 95 },
{ assignmentName: 'Assignment 03', studentName: 'Jerry', score: 100 },
{ assignmentName: 'Assignment 01', studentName: 'Ben', score: 70 }
]
/**
Include at least 5 object items in the array

Each object will have properties of
Expand All @@ -25,29 +33,52 @@

Values are important for this lesson.

- Use 2 distinct assignment names
- Use 2 distinct student names
- Use distinct assignment names
- Use only 2 distinct student names

*/

/**
/**

Looping using your preferred looping syntax and updating a shared variable
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
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 (const index in grades) {
// destructuring score
const {score } = grades[index]
console.log({score})
gradeTotal += gradeTotal
}
console.log({gradeTotal}) */
/*
gradeTotal = 0
grades.forEach( grade => {
gradeTotal += grade.score
console.log( {gradeTotal} ) */


/**

/**

Using reduce
Using reduce

3) Use Array reduce to do the same total calculation logic
3) Use Array reduce to do the same total calculation logic

Replace `null` below with the use of `reduce`
Replace `null` below with the use of `reduce`

*/
gradeTotal = null
*/
let gradeTotal = grades.reduce((total, grade) => {
//use console.log to make sure you are looking at the correct variables/properties
console.log(total, grade)
total += grade.score
return total
}, 0)

module.exports = {
grades
}