+ 1
js: function with if-statement
function p(m) { if(m==1) { return m; } else { return m*p(m-1); } } console.log(p(4)); // the right output is 24. and i dont understand it. // 4*(4-1)=12 is my opinion. what am i thinking wrong…? 🤔
3 odpowiedzi
+ 2
It is a recursive function. It is 4*3*2*1.
+ 1
It's executed as
4 * p(3)
4 * 3 * p(2)
4 * 3 * 2 * p(1)
4 * 3 * 2 * 1
24
+ 1
thank you!!! 👍