+ 2
JavaScript Function Challenge
Hello! Can someone please explain this to me? Thank you. //What is the output of this code? function p(m) { if (m==1) { return m; } else { return m * p(m-1); } } alert (p(4));
4 Answers
+ 2
Solomoni Railoa Thanks a million! This is a very clear and helpful explanation.
+ 1
Solomoni Railoa So if m had been 3, the answer would be 6? And alert (p(5)) would be 120?
+ 1
equal to:
let m = 4;
for (let mm = m - 1; mm != 1; mm = mm - 1){
m = m * mm;
}
console.log(m);
0
fan yu It looks like an alternate way to figure and output the same number.