Build a Factorial Calculator - Build a Factorial Calculator

Tell us what’s happening:

What’s wrong with my code? the test 7 ,8 and, 11 failed to run

Your code so far

let num = 1;

function factorialCalculator(number) {
  let result;

  for(let x = 1; x <= number; x++) {
    return number ** (x);
  }
}

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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36

Challenge Information:

Build a Factorial Calculator - Build a Factorial Calculator

Try working on one error at a time.

What is the first error and how can you show that your code is fulfilling that requirement?

Try testing the first example.

What does your program return when you assign 5 to num ?

It return 5 when i change the num value to 5

test your function, add console.log inside it to follow what happens
for example you could add:

function factorialCalculator(number) {
  let result;

  for(let x = 1; x <= number; x++) {
    console.log(x, 'value of x');
    return number ** (x);
  }
}

Remember that return ends the entire function immediately.

let result;

You’ve declared this result variable but never use it?

1 Like

It’s okay now i already solve the lab i just remove the return keyword, and write it inside the function, and i change the code : removed by mod

Please try not to write solution code on the forum, glad you got it