Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests for step 43 of shopping cart project #54598

Closed
juancaorg opened this issue May 1, 2024 · 1 comment · Fixed by #54631
Closed

Fix tests for step 43 of shopping cart project #54598

juancaorg opened this issue May 1, 2024 · 1 comment · Fixed by #54631
Labels
help wanted Open for all. You do not need permission to work on these. new javascript course These are for issues dealing with the new JS curriculum scope: curriculum Lessons, Challenges, Projects and other Curricular Content in curriculum directory. type: bug Issues that need priority attention. Platform, Curriculum tests (if broken completely), etc.

Comments

@juancaorg
Copy link
Contributor

Describe the Issue

When working through the Shopping Cart Step 43, it's expected from the user to create a calculateTotal() method that internally uses a reduce() to make a sum, like the following:

calculateTotal() {
  const subTotal = this.items.reduce((total, item) => total + item.price, 0);
}

But when presented the following solution, making the reduce's callback sum the other way around, it doesn't pass:

calculateTotal() {
  const subTotal = this.items.reduce((total, item) => item.price + total, 0);
}

Affected Page

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/learn-basic-oop-by-building-a-shopping-cart/step-43

Your code

calculateTotal() {
  const subTotal = this.items.reduce((total, item) => item.price + total, 0);
}

Expected behavior

Because of the Commutative property of addition, the previous presented solution should work.

Screenshots

No response

System

  • Device: Laptop
  • OS: macOS 13.6.6
  • Browser: Chrome
  • Version: 124

Additional context

No response

@juancaorg juancaorg added scope: curriculum Lessons, Challenges, Projects and other Curricular Content in curriculum directory. status: waiting triage This issue needs help from moderators and users to reproduce and confirm its validity and fix. type: bug Issues that need priority attention. Platform, Curriculum tests (if broken completely), etc. labels May 1, 2024
@jdwilkin4
Copy link
Contributor

I agree that both versions should be accepted since they are valid solutions.

@jdwilkin4 jdwilkin4 added help wanted Open for all. You do not need permission to work on these. new javascript course These are for issues dealing with the new JS curriculum and removed status: waiting triage This issue needs help from moderators and users to reproduce and confirm its validity and fix. labels May 2, 2024
@jdwilkin4 jdwilkin4 changed the title [JS Curriculum] Shopping Cart Step 43 missing commutative addition property Fix tests for step 43 of shopping cart project May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Open for all. You do not need permission to work on these. new javascript course These are for issues dealing with the new JS curriculum scope: curriculum Lessons, Challenges, Projects and other Curricular Content in curriculum directory. type: bug Issues that need priority attention. Platform, Curriculum tests (if broken completely), etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants