JavaScript Loop Programs
Practice JavaScript loops like for and while. Build tables, factorials, Fibonacci series, prime checks and number patterns, with step-by-step help and output.
6 programs · open one, then the next
Start with Multiplication Table- 01Multiplication TableBeginnerPrint a multiplication table in JavaScript using for and while loops and a reusable function. Covers off-by-one bugs, with explanation and output.Open example →js// Method 1: Using for loop let number = 5; console.log("Multiplication table of", number + ":");
- 02Sum of n Natural NumbersBeginnerFind the sum of the first n natural numbers in JavaScript with a for loop, while loop, reduce and the n(n+1)/2 formula. Clear explanation and output.Open example →js// Method 1: Using for loop let n = 10; let sum = 0;
- 03Factorial of a NumberBeginnerFind the factorial of a number in JavaScript with a for loop, recursion, while and reduce. Learn why 0! is 1 and when to use BigInt. Explanation and output.Open example →js// Factorial: n! = n × (n-1) × (n-2) × ... × 2 × 1 // Example: 5! = 5 × 4 × 3 × 2 × 1 = 120 // Method 1: Using for loop
- 04Reverse a NumberBeginnerReverse a number in JavaScript using % 10 and Math.floor, string methods and negative support. Learn why 100 becomes 1, with explanation and output.Open example →js// Method 1: Using while loop function reverseNumber(num) { let reversed = 0; let original = num;
- 05Palindrome CheckBeginnerCheck if a number or word is a palindrome in JavaScript using string reverse, digit math, two pointers and recursion, with explanation and output.Open example →js// Palindrome: reads same forwards and backwards // Examples: 121, "madam", "racecar" // Method 1: String palindrome
- 06Prime Number CheckIntermediateCheck if a number is prime in JavaScript with trial division up to the square root. Lists primes in a range and factors of 60, with explanation and output.Open example →js// Prime number: divisible only by 1 and itself // Examples: 2, 3, 5, 7, 11, 13, 17, 19 // Method 1: Basic check