Build a Factorial Calculator - Build a Factorial Calculator

Tell us what’s happening:

I’m getting error at tests 7 and 11. But when I put 5 or 7 as parameters, it returns the correct result. Don’t know what I’m doing wrong.

Your code so far

let num = 5;

const factorialCalculator = number => {
  let result = 1;
  for (let i = 1; i <= num ; i++) {
    result *= i;
  }
  return result
}

let factorial = factorialCalculator(num);
let resultMsg = `Factorial of ${num} is ${factorial}`;
console.log(resultMsg);

num = 7;

factorial = factorialCalculator(num);
resultMsg = `Factorial of ${num} is ${factorial}`;
console.log(resultMsg);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36

Challenge Information:

Build a Factorial Calculator - Build a Factorial Calculator
https://www.freecodecamp.org/learn/full-stack-developer/lab-factorial-calculator/build-a-factorial-calculator

Where is num defined? Why does the function use num and not number?

I was taking the variable declared outside the function. Changed it to the parameter and worked fine. Thanks!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.