[incorrect given solution] JavaScript Practice: Arrays, Loops, Objects, Iterators

In this exercise, I think there is mistake in first code challenge, because it gave this code solution:

// Write function below
const factorial = n => {
  let result = 1;
  
  for (let i=n; i>0; i--) {
    result *= i+1;
  }

  return result;
}

Instead of this:

// Write function below
const factorial = n => {
  let result = 1;
  
  for (let i=n; i>0; i--) {
    result *= i;
  }

  return result;
}

My Solution:

// Write function below
let factorial = (number) =>{
  let fact = 1;
  for(let i=number;i>0;i--){
    fact = fact*i;
  }
  return fact;
}
console.log(factorial(1));
4 Likes

Yea, that given solution really doesn’t work, does it.

I’ll mark this for review. Thanks for pointing it out :slight_smile:

5 Likes