r/codehs • u/Beeg_boi8 • Sep 07 '23
JavaScript Help! JavaScript 4.8.5 Factorials
I’m stuck on 4.8.5, I have it where I outputs the correct factorial but I need it to print out the whole equation. For example, if my number is 5 it should be 5 * 4 * 3 * 2 * 1 = 120. And it has to work for ANY number inputted
4
Upvotes
View all comments
Show parent comment
2
u/Beeg_boi8 Sep 08 '23
I just realized that I’m an idiot and I don’t need to change N, it’s supposed to be constant variable. I just do
println(N “ * “ + (N-1) “ * “ + (N-2) + (N-3) “ * “ + (N-4) + “ = “ + 120);
If it doesn’t work and it is supposed to be able to change then I guess will have to count down numbers until it hits 1. I’ll post my code if it works