0% found this document useful (0 votes)
13 views13 pages

JavaScript Loops and String Methods

The document provides an overview of loops in JavaScript, including for, while, do-while, for-of, and for-in loops, along with examples of their usage. It also covers strings in JavaScript, detailing how to create strings, access their length and indices, and utilize string methods such as toUpperCase and slice. Additionally, it includes practice questions to reinforce learning about loops and strings.

Uploaded by

rashidk
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views13 pages

JavaScript Loops and String Methods

The document provides an overview of loops in JavaScript, including for, while, do-while, for-of, and for-in loops, along with examples of their usage. It also covers strings in JavaScript, detailing how to create strings, access their length and indices, and utilize string methods such as toUpperCase and slice. Additionally, it includes practice questions to reinforce learning about loops and strings.

Uploaded by

rashidk
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

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”

You might also like