- 1

Why is my factorializenum number function not working please?

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

24th Apr 2017, 9:14 PM
AceDev
2 Antworten
+ 11
The 'res' in the alert() should be a variable. You did not decrare it. You did not decrare 'i' and 'a' too. Try Alberto example.
24th Apr 2017, 11:33 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 2
Look: var nu = prompt("Enter a number to factorialize"); // Request input to user function facto(nu){ // Create function with parameter var a , c = 1; // Initialize c = 1 for (a = 1; a <= nu; a++){ // Loop until nu less or equal to nu c *= a; // while c x a = x1 } // x1 x a = x2 // x2 x a = x3... return c; // Return factorial } alert("factorialized is: " + facto(nu)); // Call function created and print Good Luck!
24th Apr 2017, 9:56 PM
Alberto Del Angel
Alberto Del Angel - avatar