diff --git a/08_calculator/calculator.js b/08_calculator/calculator.js index c22e8d2..2b97217 100644 --- a/08_calculator/calculator.js +++ b/08_calculator/calculator.js @@ -1,6 +1,6 @@ -const add = function() { - -}; + const add=(num1,num2)=>{ + return num1+num2; + } const subtract = function() { @@ -14,13 +14,26 @@ const multiply = function() { }; -const power = function() { - +const power = function(num,power) { + let rez=1; +for(let i=1;i<=power;i++){ + rez*=num; }; +return rez +} -const factorial = function() { - -}; + +const factorial = (num) =>{ + let res=1; + + for(i=1;i<=num;i++){ + res*=i; + } + + + return res; + } + // Do not edit below this line module.exports = { diff --git a/08_calculator/calculator.spec.js b/08_calculator/calculator.spec.js index dc317ec..bcd0fdf 100644 --- a/08_calculator/calculator.spec.js +++ b/08_calculator/calculator.spec.js @@ -5,11 +5,11 @@ describe('add', () => { expect(calculator.add(0,0)).toBe(0); }); - test.skip('adds 2 and 2', () => { + test('adds 2 and 2', () => { expect(calculator.add(2,2)).toBe(4); }); - test.skip('adds positive numbers', () => { + test('adds positive numbers', () => { expect(calculator.add(2,6)).toBe(8); }); }); @@ -49,29 +49,29 @@ describe('multiply', () => { }); describe('power', () => { - test.skip('raises one number to the power of another number', () => { + test('raises one number to the power of another number', () => { expect(calculator.power(4,3)).toBe(64); // 4 to third power is 64 }); }); describe('factorial', () => { - test.skip('computes the factorial of 0', () => { + test('computes the factorial of 0', () => { expect(calculator.factorial(0)).toBe(1); // 0! = 1 }); - test.skip('computes the factorial of 1', () => { + test('computes the factorial of 1', () => { expect(calculator.factorial(1)).toBe(1); }); - test.skip('computes the factorial of 2', () => { + test('computes the factorial of 2', () => { expect(calculator.factorial(2)).toBe(2); }); - test.skip('computes the factorial of 5', () => { + test('computes the factorial of 5', () => { expect(calculator.factorial(5)).toBe(120); }); - test.skip('computes the factorial of 10', () => { + test('computes the factorial of 10', () => { expect(calculator.factorial(10)).toBe(3628800); }); });