function myfact(number) { var fact = 1; var i = 1; while (i <= number) { fact = fact * i; i++; } return fact; } console.log(myfact(6)); //Output: 720