- 1
Why is my factorializenum number function not working please?
2 Respostas
+ 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.
+ 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!