wrote the factorial function to match the test conditions