Skip to content

Commit 720733e

Browse files
committed
Impelment receipt function using destructuring and same format
1 parent 002a1ef commit 720733e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Sprint-1/destructuring/exercise-3/exercise.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,19 @@ let order = [
66
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
77
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
88
];
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

Comments
 (0)