Skip to content
Exit presentation

Data Handling I: Organizing & Visualizing Data

Total divided by count

One number for the whole week. Share the week's total equally between the days. What each day holds is the mean.

Loading lab…

Seven bars for the week. Values shown above each one.
Step 1 of 4
  1. Seven bars for the week. Values shown above each one.
  2. All seven add up. Total = 70.
  3. Seven days in the list. Count = 7.
  4. Mean = 70 ÷ 7 = 10, ruled across the strip.

The rule

A function is a named set of lines. This function gives back one answer.

The mean is the total divided by the count. Written as a function, it works on any list you hand it. Longer or shorter, the lines do not change.

  • let total = 0; — the box, outside the loop.
  • total = total + day; — each reading added on.
  • return total / days.length; — divide, then give back the answer. The sign / means divide.

The count comes from .length. Nothing is counted by hand.

Monday to Saturday is six days, total 66. The mean is 66 ÷ 6 = 11. The whole week is seven days, total 70. Its mean is 70 ÷ 7 = 10.

If Tuesday were 45, not 46, the total is 70 − 1 = 69. 7 does not divide 69 evenly. The machine prints 9.857142857142858. It does not round the answer.

Jump to lesson

This track

  1. 0 Start here
  2. 1 One list holds the whole week
  3. 2 Every item has a position
  4. 3 A list the program builds itself
  5. 4 One box outside the loop
  6. 5 Total divided by count
  7. 6 The biggest, without sorting
  8. 7 One count per group
  9. 8 The chart the program drew
  10. 9 The big picture
  11. 10 Track quiz

Other tracks