- 1
Why is my if statement not taken into account inside this function?
2 Réponses
+ 4
Your 'if' statement works, so if user input zero, you document.write('1'), but you also write the returned value of your factorial function ^^
Change your code by adding the 'else' keyword before the call to your factorial function:
if (nu===0){
document.write(1);
}
else document.write(fac(nu));
[edit]
Another way is to test the 0 case inside your factorial function ;)
0
delete this
if (nu===0){
document.write(1);
}
and run this
document.write(nu===0?1:fac(nu));