Synvara
TOOLS
Games
Blog
Contact
Menu
Initializing Synvara System...
← Back to Tools
Text Diff Checker
Compare two texts side-by-side and see the differences highlighted.
Original
10 lines
function calculateTotal(items) { let total = 0; for (let i = 0; i < items.length; i++) { total += items[i].price; } return total; } const result = calculateTotal(cart); console.log(result);
Modified
11 lines
function calculateTotal(items, taxRate = 0) { let total = 0; for (const item of items) { total += item.price * item.quantity; } const tax = total * taxRate; return total + tax; } const result = calculateTotal(cart, 0.08); console.log(`Total: $${result.toFixed(2)}`);
Swap
Copy Diff
Clear
+7 added
−6 removed
4 unchanged
Unified Diff
17 lines
1
−
function calculateTotal(items) {
1
+
function calculateTotal(items, taxRate = 0) {
2
2
let total = 0;
3
−
for (let i = 0; i < items.length; i++) {
4
−
total += items[i].price;
3
+
for (const item of items) {
4
+
total += item.price * item.quantity;
5
5
}
6
−
return total;
6
+
const tax = total * taxRate;
7
+
return total + tax;
7
8
}
8
9
9
−
const result = calculateTotal(cart);
10
−
console.log(result);
10
+
const result = calculateTotal(cart, 0.08);
11
+
console.log(`Total: $${result.toFixed(2)}`);