diff --git a/src/alignString.js b/src/alignString.js index f0383ff..3e24fb5 100644 --- a/src/alignString.js +++ b/src/alignString.js @@ -35,7 +35,7 @@ const alignCenter = (subject, width) => { halfWidth = width / 2; - if (halfWidth % 2 === 0) { + if (width % 2 === 0) { return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth); } else { halfWidth = Math.floor(halfWidth); diff --git a/test/alignString.js b/test/alignString.js index eb57893..045a15a 100644 --- a/test/alignString.js +++ b/test/alignString.js @@ -64,7 +64,7 @@ describe('alignString', () => { }); context('center', () => { it('pads the string on both sides using a whitespace character', () => { - expect(alignString('aa', 6, 'center')).to.equal(' aa '); + expect(alignString('aa', 8, 'center')).to.equal(' aa '); }); context('uneven number of available with', () => { it('floors the available width; adds extra space to the end of the string', () => {