-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx9.js
More file actions
31 lines (21 loc) · 687 Bytes
/
Ex9.js
File metadata and controls
31 lines (21 loc) · 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/** Create array of items using the push method and pass this array into a function called: calculateTotal.
* This function calculates the total of all the items.
Output: */
const calculateTotal = (itemArray) => {
let total = 0;
for(let i = 0; i < itemArray.length; i++){
total += itemArray[i].cost * itemArray[i].quantity;
}
console.log(total);
}
const main = () => {
let item1 = { quantity: 1, cost: 1.00 }
let item2 = { quantity: 2, cost: 2.00 }
let item3 = { quantity: 3, cost: 3.00 }
let itemArray = [];
itemArray.push(item1);
itemArray.push(item2);
itemArray.push(item3);
calculateTotal(itemArray);
}
main();