Grokking Node.js
0% completed
Debugging Node.js Applications with Console and VS Code
The function below should add three prices and print 40. Save it as cart.js and run it with node cart.js.
function cartTotal(items) { let total = 0; for (const item of items) { total += item.price; } return total; } const items = [ { name: "Pen", price: 3 }, { name: "Notebook", price: "12" }, { name: "Bag", price: 25 } ]; console.log("Total:", cartTotal(items));
Total: 31225
The program does not crash, and it prints no error. It simply gives a wrong answer
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%