Question
Modify the following code so that the output goes from myFactorial output 0 to 10:0! = 11! = 12! = 23! = 64! = 245!
Modify the following code so that the output goes from
myFactorial output 0 to 10:0! = 11! = 12! = 23! = 64! = 245! = 1206! = 7207! = 5,0408! = 40,3209! = 362,88010! = 3,628,800
to
myFactorial output 0 to 10:
0! = 1 1! = 1 2! = 2 3! = 6 4! = 24 5! = 120 6! = 720 7! = 5,040 8! = 40,320 9! = 362,880 10! = 3,628,800
// factorial function
function myFactorial(num){
// if number is zero return 1
if(num==0){
return 1;
}
else{
// recursive call.
return num*myFactorial(num-1);
}
}
// loop to print factorial values
document.write('myFactorial output 0 to 10:');
for(var i=0;i<11;i++){
document.write(i.toLocaleString()+"! = " + myFactorial(i).toLocaleString());
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started