Skip to content

Shopping Cart Step 44 does not accept explicit return in reduce callback #67841

@caiolucasbittencourt

Description

@caiolucasbittencourt

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope: curriculumLessons, Challenges, Projects and other Curricular Content in curriculum directory.status: waiting triageThis issue needs help from moderators and users to reproduce and confirm its validity and fix.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions