We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 002a1ef commit 720733eCopy full SHA for 720733e
Sprint-1/destructuring/exercise-3/exercise.js
@@ -6,3 +6,19 @@ let order = [
6
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
7
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
8
];
9
+function receipt(arr){
10
+ let total=0;
11
+ const firstLine="QTY".padEnd(8)+"ITEM".padEnd(20)+"Total";
12
+ console.log(firstLine);
13
+
14
15
+arr.forEach(({itemName,quantity,unitPricePence})=> {
16
+ itemPrice=unitPricePence*quantity/100;
17
+ const line=String(quantity).padEnd(8)+itemName.padEnd(20)+itemPrice.toFixed(2);
18
+ console.log(line);
19
+ total+=itemPrice
20
+})
21
+console.log(`\nTotal: ${total.toFixed(2)}`)
22
+}
23
24
+receipt(order);
0 commit comments