Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update exercise-3.js
  • Loading branch information
GTabala committed Sep 29, 2020
commit c6c25c5690af65a181a96844fe95f9d1400e2d40
12 changes: 4 additions & 8 deletions week-3/Homework/mandatory/2-exercises/exercise-3/exercise-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@ let order = [
{ itemName: "Hash Brown", quantity: 4, unitPrice: 0.4 },
];

function getSpaces(words, length) {
while (("" + words).length < length) {
words += " ";
}
return words;
}
console.log("QTY".padEnd(8), "ITEM".padEnd(20), "TOTAL");

console.log(getSpaces("QTY", 8) + getSpaces("ITEM", 20) + "TOTAL");
let total = 0;
order.forEach((item) => {
let { itemName, quantity, unitPrice } = item;
let sum = quantity * unitPrice;
total += sum;
console.log(
getSpaces(quantity, 8) + getSpaces(itemName, 20) + sum.toFixed(2)
("" + quantity).padEnd(8),
itemName.padEnd(20),
sum.toFixed(2)
);
});
console.log("");
Expand Down