CJCoding With Joseph
15free / daySign inCreate account

Sum and Average with forEach

You can use forEach together with a variable that lives outside the loop to build up a running total. You are given an array of grades. Use forEach to add every grade into a total, then print "Sum: " followed by the total, and on the next line print "Average: " followed by the total divided by the number of grades.

Expected Output:

Sum: 340
Average: 85

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Arrays
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (clog, fn, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.