Skip to content

Commit 4213201

Browse files
committed
Fix totalTill function to handle unrecognized coins and update total calculation
1 parent 61584ba commit 4213201

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Sprint-2/stretch/till.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ function totalTill(till) {
88
let total = 0;
99

1010
for (const [coin, quantity] of Object.entries(till)) {
11-
total += parseInt(coin) * quantity;
11+
total += coinValues[coin] * quantity;
12+
if (!(coin in coinValues)) {
13+
throw new Error(`Coin ${coin} is not recognized`);
14+
}
1215
}
1316

1417
return ${(total / 100).toFixed(2)}`;

0 commit comments

Comments
 (0)