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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy