Skip to content

Worked on bowling TDD#1

Open
kiyaGu wants to merge 8 commits into
snozza:masterfrom
kiyaGu:master
Open

Worked on bowling TDD#1
kiyaGu wants to merge 8 commits into
snozza:masterfrom
kiyaGu:master

Conversation

@kiyaGu

@kiyaGu kiyaGu commented Aug 1, 2017

Copy link
Copy Markdown

I have done the bowling TDD assignment

@snozza snozza self-requested a review August 3, 2017 06:55

@snozza snozza left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good work - a few comments :)

Comment thread bowling.js Outdated
BowlingGame.prototype.calculateSpareBonus = function(frameIndex){
return this.rolls[frameIndex + 2];
}
BowlingGame.prototype.calculateStrikeBonus = function(frameIndex){

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions/Methods should do one thing - This should only calculate the Strike bonus.

However, it is also checking what roll the person is at - refactor this out of the function.

Tip: A strike bonus calculation will always be the same, regardless of what roll it is.

Comment thread bowling.js
}
}
}
BowlingGame.prototype.roll = function(pins) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Roll method is doing too much - it should just roll, it should not be checking the number of pins.

Tip: This can be a single line function

Comment thread bowling.test.js Outdated
game.roll(9);
game.roll(1);
game.roll(10);
let score = game.score();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be const - be consistent with use of consts/lets

Comment thread bowling.test.js Outdated
test('handle a bonus for spare', () => {
rollMany(2, 5);
game.roll(4);
let bonus = game.calculateSpareBonus(0);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be const - be consistent with use of consts/lets

Comment thread bowling.test.js Outdated
rollMany(1, 10);
game.roll(8);
game.roll(6);
let bonus = game.calculateStrikeBonus(0);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be const - be consistent with use of consts/lets

Comment thread bowling.js
this.rolls.push(pins);
}
}
BowlingGame.prototype.score = function() {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to use this method to calculate the score without checking what index the roll is -

Think about iterating through frames instead of rolls.

Comment thread bowling.js
index++; // move to the next frame
} else if (this.isSpare(this.rolls[index], this.rolls[index + 1])) {
//add the two rolls in the current frame and the bonus for spare
sum += this.rolls[index] + this.rolls[index + 1] + this.calculateSpareBonus(index);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repetition - anytime you see the exact same thing 2 or more times, you should think about whether or not it should be moved into a separate function (or variable if it is a variable)

Comment thread bowling.js
index += 2; // move to the next frame
} else {
//add the two rolls in the current frame
sum += this.rolls[index] + this.rolls[index + 1];

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repetition - anytime you see the exact same thing 2 or more times, you should think about whether or not it should be moved into a separate function (or variable if it is a variable)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants