thecodezone.
The Code Zone
Short steps, at your pace · Free lessons and practice · Member video walkthroughs
Save your next small win.

Checking your account…

19.09 · Arrays / Practice · 6 min

Find the bowling average

A six-game total is not a per-game average. Divide by the current game count.

Activity 9 of 15 in Arrays

All courses

JavaScript Basics / 19.09

Find the bowling average

Not started

A six-game total is not a per-game average. Divide by the current game count.

More options
Rob totals six bowling scores to 1105, counts six games and shows a rounded average of 184.
Rob’s comic strip · Arrays

Add array values and calculate an average

Work through 4 focused steps. Read the explanation, type each requested change and check it before moving on. Your own code carries forward.

The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.

Start mini-lesson(opens in a new tab)

4 steps · Saved work · Instant feedback

YOUR TURN

Divide the score total by the game count

Repair averageScore(scores) for a nonempty array of numeric scores: return the total divided by scores.length. Keep scoreTotal, all six original scores, and both output calls. Print Total: 1105 and Average: 184. The average helper must return an unrounded number; only the displayed output uses toFixed(0).

Expected output
Total: 1105
Average: 184

Keep the starting inputs. Print these lines in this order, without extra output.

Edit JavaScript, then run it. Check Challenge shows which output checks pass or need a fix. Word wrap is enabled.

Ready to checkRun the checks to see your results here.

Work in VS Code instead

Copy the starter into a file named practice.js in VS Code. If Node.js is installed, open the terminal in that folder and run node practice.js. Compare the output with the task above. Automated challenge checks are available in the browser editor.

Code example
example.jsjavascript · example
function scoreTotal(scores) {
  let total = 0;
  for (let i = 0; i < scores.length; i++) {
    total += scores[i];
  }
  return total;
}
function averageScore(scores) {
  return scoreTotal(scores);
}
const bowler1Scores = [167, 188, 179, 161, 201, 209];
console.log("Total: " + scoreTotal(bowler1Scores));
console.log("Average: " + averageScore(bowler1Scores).toFixed(0));

Need a nudge?

A total and an average answer different questions

1105 is the combined score for six games. Divide that total by scores.length to find the per-game average.

Keep calculation separate from presentation

Return the numeric division result. The existing output line applies toFixed(0), rounding the displayed value to a whole number.

Replace your editor code?

Your current work will be replaced. Choose Cancel to keep it.

Ready to try it?

Practice in your browser and see your results.

Progress details

Have a question?

Ask the Code Zone community.

Ask a question in The Code Zone (opens in a new tab)

Continue learning

ONE STEP FORWARD

Read one value at a time and keep track of what each index or total means.