Created
January 30, 2012 23:14
-
-
Save karlwestin/1707413 to your computer and use it in GitHub Desktop.
The Bowling Kata, written in javascript, "score" function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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