-1
Good evening, I made the following algorithm in Javascript:
var res = 1;
console.log(fatorial(3));
function fatorial(n){
if(n == 1){
console.log(res);
return(res);
}else{
res *= n;
fatorial(n - 1);
}
}
In the console.log(res) the result appears correctly, while in console.log(factorial(3)) message appears Undefined. Someone could explain to me the reason for this and how to make the result appear in both?
Thanks in advance for your attention.
Thank you very much! It was something I did not notice, solved my problem.
– Lucas Mateus Menezes Silva