← Back to challenges

Bowling Scorekeeping

JavaScriptHardgamesnumbers

Instructions

Tenpin bowling scores can range from 0 (all gutter balls) to 300 (a perfect game).

A complete record of a 10 frame bowling game can be given as an array of the number of pins knocked down by each ball in sequence from the beginning to the end of the game.

Create a function whose argument is such an array. The function should return the final score.

Examples

bowling([10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) ➞ 300

bowling([4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) ➞ 80

bowling([5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) ➞ 150

bowling([10, 5, 5, 10, 5, 5, 10, 5, 5, 10, 5, 5, 10, 5, 5, 10]) ➞ 200

Notes

The number of balls thrown for a complete game can vary from 12 to 21 depending on the number of strikes and spares thrown.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.