8000 Add return value that adds variables together for the add function. A… · rhawkenson/javascript-exercises@726ff8b · GitHub
[go: up one dir, main page]

Skip to content

Commit 726ff8b

Browse files
committed
Add return value that adds variables together for the add function. Add return value that subtracts variables for the subtract function.
1 parent 8882f54 commit 726ff8b

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

calculator/calculator.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
function add () {
2-
1+
function add (num1, num2) {
2+
return num1 + num2;
33
}
44

5-
function subtract () {
6-
5+
function subtract (num1, num2) {
6+
return num1 - num2;
77
}
88

9-
function sum () {
10-
9+
function sum (arr) {
10+
let total = 0;
11+
for (let i=0; i<arr.length-1; i++){
12+
total += arr[i];
13+
return total;
14+
}
1115
}
1216

1317
function multiply () {

calculator/calculator.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@ describe('add', function() {
55
expect(calculator.add(0,0)).toEqual(0);
66
});
77

8-
xit('adds 2 and 2', function() {
8+
it('adds 2 and 2', function() {
99
expect(calculator.add(2,2)).toEqual(4);
1010
});
1111

12-
xit('adds positive numbers', function() {
12+
it('adds positive numbers', function() {
1313
expect(calculator.add(2,6)).toEqual(8);
1414
});
1515
});
1616

1717
describe('subtract', function() {
18-
xit('subtracts numbers', function() {
18+
it('subtracts numbers', function() {
1919
expect(calculator.subtract(10,4)).toEqual(6);
2020
});
2121
});
2222

2323
describe('sum', function() {
24-
xit('computes the sum of an empty array', function() {
24+
it('computes the sum of an empty array', function() {
2525
expect(calculator.sum([])).toEqual(0);
2626
});
2727

28-
xit('computes the sum of an array of one number', function() {
28+
it('computes the sum of an array of one number', function() {
2929
expect(calculator.sum([7])).toEqual(7);
3030
});
3131

32-
xit('computes the sum of an array of two numbers', function() {
32+
it('computes the sum of an array of two numbers', function() {
3333
expect(calculator.sum([7,11])).toEqual(18);
3434
});
3535

36-
xit('computes the sum of an array of many numbers', function() {
36+
it('computes the sum of an array of many numbers', function() {
3737
expect(calculator.sum([1,3,5,7,9])).toEqual(25);
3838
});
3939
});

0 commit comments

Comments
 (0)
0