Skip to content

Instantly share code, notes, and snippets.

@karlwestin
Created January 30, 2012 23:14
Show Gist options
  • Save karlwestin/1707413 to your computer and use it in GitHub Desktop.
Save karlwestin/1707413 to your computer and use it in GitHub Desktop.
The Bowling Kata, written in javascript, "score" function
// This is the implementation from https://github.com/zachleat/JavaScript-Code-Katas
Game.prototype.score = function()
{
var points = 0,
frameIndex = 0;
for(var frame = 0; frame<10; frame++) {
if(this.isStrike(frameIndex)) {
points += this.strikeBonus(frameIndex);
frameIndex++;
} else if(this.isSpare(frameIndex)) {
points += this.spareBonus(frameIndex);
frameIndex += 2;
} else {
points += this.sumOfBallsInFrame(frameIndex);
frameIndex += 2;
}
}
return points;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment