Loops in JS
Loops are used to execute a piece of code
again & again
for Loop
for (let i = 1; i <= 5; i++) {
[Link]("apna college");
}
Loops in JS
Infinite Loop : A Loop that
never ends
Loops in JS
while Loop
while
(condition) {
// do some
work
}
Loops in JS
do-while Loop
do {
// do some
work
} while
(condition);
Loops in JS
for-of Loop
for (let val of
strVar) {
//do some work
}
Loops in JS
for-in Loop
for (let key in
objVar) {
//do some work
}
Let‘s Practice
Qs1. Print all even numbers from 0 to 100.
Let‘s Practice
Qs2.
Create a game where you start with any random game number. Ask the
user to keep guessing the game number until the user enters correct
value.
Strings in JS
String is a sequence of characters used to
represent text
Create String
let str = “Apna College“;
String Length
[Link]
String Indices
str[0], str[1],
str[2]
Template Literals in JS
A way to have embedded expressions in
strings
`this is a template literal`
String Interpolation
To create strings by doing substitution of
placeholders
`string text ${expression} string text`
String Methods in
JS are built-in functions to manipulate
These
a string
[Link]( )
[Link]( )
[Link]( ) // removes whitespaces
String Methods in
JS
[Link](start, end?) // returns part of
string
[Link]( str2 ) // joins str2
with str1
[Link]( searchVal,
newVal )
[Link]( id
x)
Let‘s Practice
Qs1. Prompt the user to enter their full name. Generate a username for them
based on the input. Start username with @, followed by their full name and
ending with the fullname length.
eg: user name = “shradhakhapra” , username should be
“@shradhakhapra13”