Hi team,
I was trying to solve factorial number of my own logic and I get some weird result, below is my code please help me with this
function Fact(n){
var m = n; //console.log(m) // 5 initially
if(m === 1){return 1}
for(var i=m; i>=1; i–){
m*=i-1; //console.log(m); // I get 120 here
}
return m; // this return statement is always 0, I’m not getting 120
}
Fact(5);
for(var i=m; i>=1; i–){ // i guess there typo here it should be i-- not i-
m*=i-1; // when i be 1 then m will be m*=i-1 (which will be 0) which make m to be 0
there a missing semicolon at the end of return 1;
notice that your email is visible so try to change your profile setting to hide it
it would be better to share your code on any online service like codepen.io jsfiddle github glitch in your future post