0% found this document useful (0 votes)
2 views

JS3 ClassNotes

The document provides an overview of loops in JavaScript, including for, while, do-while, for-of, and for-in loops, along with examples of each. It also covers strings in JavaScript, explaining string creation, length, indices, template literals, and various string methods. Additionally, it includes practice questions for applying these concepts.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

JS3 ClassNotes

The document provides an overview of loops in JavaScript, including for, while, do-while, for-of, and for-in loops, along with examples of each. It also covers strings in JavaScript, explaining string creation, length, indices, template literals, and various string methods. Additionally, it includes practice questions for applying these concepts.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Loops in JS

Loops are used to execute a piece of code again & again

for Loop

for (let i = 1; i <= 5; i++) {

console.log("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

str.length

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
These are built-in functions to manipulate a string

str.toUpperCase( )

str.toLowerCase( )

str.trim( ) // removes whitespaces


String Methods in JS
str.slice(start, end?) // returns part of string

str1.concat( str2 ) // joins str2 with str1

str.replace( searchVal, newVal )

str.charAt( idx )
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