Describe the Issue
In the Shopping Cart workshop, Step 44 does not seem to accept a reduce callback with an explicit return.
It passes when using an implicit return, but fails with the equivalent explicit return version.
Affected Page
https://www.freecodecamp.org/learn/javascript-v9/workshop-shopping-cart/step-44
Your code
calculateTotal() {
const subTotal = this.items.reduce((total, item) => {
return total + item.price;
}, 0);
}
Expected behavior
The explicit return version should pass because it follows the step instructions: it uses reduce, uses total and item as the callback parameters, sums the item prices, and sets the initial value to 0.
Currently, this version does not pass:
calculateTotal() {
const subTotal = this.items.reduce((total, item) => {
return total + item.price;
}, 0);
}
But this version passes:
calculateTotal() {
const subTotal = this.items.reduce((total, item) => total + item.price, 0);
}
Screenshots
No response
System
- Device: Desktop
- OS: Windows 11
- Browser: Chrome
- Version: 147.0
Additional context
No response
Describe the Issue
In the Shopping Cart workshop, Step 44 does not seem to accept a
reducecallback with an explicitreturn.It passes when using an implicit return, but fails with the equivalent explicit return version.
Affected Page
https://www.freecodecamp.org/learn/javascript-v9/workshop-shopping-cart/step-44
Your code
Expected behavior
The explicit return version should pass because it follows the step instructions: it uses
reduce, usestotalanditemas the callback parameters, sums the item prices, and sets the initial value to0.Currently, this version does not pass:
But this version passes:
Screenshots
No response
System
Additional context
No response