Skip to content

Factorial Calculator only accepts regular function #69484

Closed

Description

@dinahess

Describe the Issue

The tests do not support an arrow function even if it's declared with let. Please refer to this forum post: https://forum.freecodecamp.org/t/build-a-factorial-calculator-build-a-factorial-calculator/797404/2

Affected Page

https://www.freecodecamp.org/learn/javascript-v9/lab-factorial-calculator/build-a-factorial-calculator

Steps to Reproduce

Enter code from the above post. It does not pass the tests.

Recommended fix or suggestions

Fix the tests to allow both an arrow function or regular function or add a note to the instructions letting users know the tests will only accept a regular function.

Screenshots

No response

Activity

  1. added theissue type on Aug 11, 2026
  2. added
    status: waiting triage
    on Aug 11, 2026
  3. jacobptnguyen commented on Aug 11, 2026

    @jacobptnguyen
    Contributor

    Hi @maintainers, I've reproduced this. The test uses factorialCalculator.toString() to check the function was declared with an argument, but that only works for named function declarations: arrow functions' .toString() doesn't include the variable name, so valid arrow-function solutions fail. I opened a fix in #69488 (swaps the toString-regex check for factorialCalculator.length === 1, which works for both styles). Would appreciate a triage when you get a chance so it can move forward, thanks!

  4. imsomilg commented on Aug 13, 2026

    @imsomilg
    Member

    The test code for the following hint should be updated to support all three types of functions: function declarations, function expressions, and arrow functions.

    The factorialCalculator function should take a number as an argument.

    Instead of regex, we can use the allFunctions and parameters AST helpers. You can check the docs for help with implementing this.

  5. added
    help wanted
    and removed
    status: waiting triage
    on Aug 13, 2026
  6. jacobptnguyen commented on Aug 14, 2026

    @jacobptnguyen
    Contributor

    Hi @imsomilg, I implemented the changes you requested. Please review the PR, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wanted

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions