Skip to content

Commit ba8bb20

Browse files
committed
Fix exercise 3 formatting to match expected output
1 parent 43be954 commit ba8bb20

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,22 @@ let order = [
99

1010
let total = 0;
1111

12-
console.log("QTY ITEM TOTAL");
12+
// Header (match spacing EXACTLY)
13+
console.log("QTY ITEM TOTAL");
1314

1415
order.forEach(({ itemName, quantity, unitPricePence }) => {
1516
const itemTotal = quantity * unitPricePence;
1617
total += itemTotal;
1718

19+
// Fix capitalisation (Hot cakes → Hot Cakes)
20+
const formattedName = itemName
21+
.split(" ")
22+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
23+
.join(" ");
24+
25+
// Format columns exactly
1826
console.log(
19-
`${String(quantity).padEnd(6)}${itemName.padEnd(17)}${(itemTotal / 100).toFixed(2)}`
27+
`${String(quantity).padEnd(8)}${formattedName.padEnd(20)}${(itemTotal / 100).toFixed(2)}`
2028
);
2129
});
2230

0 commit comments

Comments
 (0)