0% found this document useful (0 votes)
1 views7 pages

05 - Loops in JavaScript

The document discusses loops in JavaScript, detailing the core types: for, while, do-while, for-of, and for-in. It emphasizes the importance of avoiding infinite loops and presents several challenges for practice, including calculating sums and creating simple games. Additionally, it suggests building a text-based adventure game as a project.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views7 pages

05 - Loops in JavaScript

The document discusses loops in JavaScript, detailing the core types: for, while, do-while, for-of, and for-in. It emphasizes the importance of avoiding infinite loops and presents several challenges for practice, including calculating sums and creating simple games. Additionally, it suggests building a text-based adventure game as a project.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Loops In JavaScript:

Loops in JavaScript are a way to repeat a block of code multiple times.

Types of Loops in JavaScript :


1. for
2. while Core Loops
3. do-while
4. for-of (arrays, strings, maps or sets [don’t care about index])
5. for-in (iterating over the properties (keys) of an object or the indexes of an array)
for loop

while loop

Note:
❑ Avoid infinite loop
do-while loop
for-of loop

for-in loop
Challenge 1:

Solution:

Challenge 2:

Solution:
1. Calculate sum of first ‘n’ numbers.
2. Calculate the sum of numbers from ‘m’ to ‘n’.
3. Print all odd numbers from 0 to ‘n’.
4. Create a “Number Knock” game. (ask the user to keep guessing the number
until the user enters correct guess) .
5. Simple Password Checker (Fixed Attempts)
6. Create a program to find the factorial of ‘n’.
7. Print the following pattern. (build it for nth numbers)
Build a Simple Text-Based Adventure Game

You might also like