Skip to content

Commit 385f75b

Browse files
committed
total
1 parent 44e3e9a commit 385f75b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

25_total.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// function , array, condition
2+
3+
const gas = [10, 10, 10, 10];
4+
const food = [10, 100];
5+
6+
function calculateTotal(arr) {
7+
// loop
8+
let total = 0;
9+
for (let i = 0; i < arr.length; i++) {
10+
// for totally
11+
total += arr[i];
12+
}
13+
if (total > 100) {
14+
console.log('Total bigger than 40');
15+
} else {
16+
console.log('Total smaller then 40');
17+
}
18+
return total;
19+
}
20+
21+
const gasTotal = calculateTotal(gas);
22+
const foodTotal = calculateTotal(food);
23+
console.log({
24+
gas: gasTotal,
25+
food: foodTotal,
26+
});

0 commit comments

Comments
 (0)