Find Factorial of a Number in JavaScript using For loop - JavaScript Tutorial 66
35.2 هزار بار بازدید -
7 سال پیش
-
Notes for You:: Find Factorial
Notes for You:: Find Factorial of a Number in JavaScript
Logic:
1! = 1
2! = 2 x 1 = 2
3! = 3 x 2 x 1= 6
4! = 4 x 3 x 2 x 1 = 24
5! = 5 x 4 x 3 x 2 x 1 = 120
i.e. n! = n x (n-1) x (n-2) x ….. x 1
Code:
var num=3;
var fact=1;
for(var i=num; i>=1; i--)
{
fact = fact * i;
}
document.write(fact); // 6
Note:
- replace > with greater-than symbol.
=========================================
Follow the link for next video:
JavaScript Tutorial 67 - Find factorial of a number using recursive function in JavaScript
Find Factorial of a Number in JavaScr...
Follow the link for previous video:
JavaScript Tutorial 65 - Calling a function inside another function in JavaScript
How to Call a Function inside another...
=========================================
JavaScript Tutorials Playlist:-
JavaScript Tutorials
=========================================
Watch My Other Useful Tutorials:-
jQuery Tutorials Playlist:-
jQuery Tutorials
jQuery UI Tutorials Playlist:-
jQuery UI Tutorials
Bootstrap Tutorials Playlist:-
Bootstrap Tutorials
=========================================
► Subscribe to our YouTube channel:
chidrestechtutorials
► Visit our Website:
https://www.chidrestechtutorials.com
=========================================
Hash Tags:-
#ChidresTechTutorials #JavaScript #JavaScriptTutorial
Logic:
1! = 1
2! = 2 x 1 = 2
3! = 3 x 2 x 1= 6
4! = 4 x 3 x 2 x 1 = 24
5! = 5 x 4 x 3 x 2 x 1 = 120
i.e. n! = n x (n-1) x (n-2) x ….. x 1
Code:
var num=3;
var fact=1;
for(var i=num; i>=1; i--)
{
fact = fact * i;
}
document.write(fact); // 6
Note:
- replace > with greater-than symbol.
=========================================
Follow the link for next video:
JavaScript Tutorial 67 - Find factorial of a number using recursive function in JavaScript
Find Factorial of a Number in JavaScr...
Follow the link for previous video:
JavaScript Tutorial 65 - Calling a function inside another function in JavaScript
How to Call a Function inside another...
=========================================
JavaScript Tutorials Playlist:-
JavaScript Tutorials
=========================================
Watch My Other Useful Tutorials:-
jQuery Tutorials Playlist:-
jQuery Tutorials
jQuery UI Tutorials Playlist:-
jQuery UI Tutorials
Bootstrap Tutorials Playlist:-
Bootstrap Tutorials
=========================================
► Subscribe to our YouTube channel:
chidrestechtutorials
► Visit our Website:
https://www.chidrestechtutorials.com
=========================================
Hash Tags:-
#ChidresTechTutorials #JavaScript #JavaScriptTutorial
7 سال پیش
در تاریخ 1396/10/12 منتشر شده
است.
35,231
بـار بازدید شده