SHARE
TWEET

Untitled

a guest Jun 19th, 2017 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use script';
  2.  
  3. function Frame(){
  4.   this.MAXSCORE = 10;
  5.   this.MAXROLLS = 2;
  6.   this.rolls = [];
  7.   this.isSpare = false;
  8.   this.isStrike = false;
  9.   this.isComplete = false;
  10. }
  11.  
  12. Frame.prototype.addRoll = function(roll){
  13.   if (!(this.isComplete) && roll <= this.MAXSCORE) this.rolls.push(roll);
  14.   if (roll === this.MAXSCORE && this.rolls.length < this.MAXROLLS) this.isStrike = true, this.isComplete = true;
  15.   if (this.rolls.length === this.MAXROLLS && this.score() === this.MAXSCORE) this.isSpare = true;
  16.   if (this.rolls.length === this.MAXROLLS) this.isComplete = true;
  17. };
  18.  
  19. Frame.prototype.score = function(){
  20.   return this.rolls.reduce(function (total, roll){
  21.     return total + roll;
  22.   });
  23. };
  24.  
  25. module.exports = Frame;
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top