Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to sum variables to an array in javascript

function sumGrades(grades) {
    let sum =0;
    grades.forEach(function(grade){
        sum += grade;
    })
    return sum;
}

// Sample usage - do not modify
console.log(sumGrades([15, 5, 10])); // 30
console.log(sumGrades([12, 10, 13, 19])); // 54
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sum #variables #array #javascript
ADD COMMENT
Topic
Name
3+8 =