Why is my if statement not taken into account inside this function? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
- 1

Why is my if statement not taken into account inside this function?

https://code.sololearn.com/W2VV2NEzWsg4/?ref=app

25th Apr 2017, 1:31 PM
AceDev
2 Respuestas
+ 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 ;)
25th Apr 2017, 4:05 PM
visph
visph - avatar
0
delete this if (nu===0){ document.write(1); } and run this document.write(nu===0?1:fac(nu));
25th Apr 2017, 1:39 PM
Yaroslav Pieskov
Yaroslav Pieskov - avatar