JS_PPT
JS_PPT
Javascript
ID Name Age
1.1 Raj 18
Memory
Rules of variable
• Variable names are case sensitive : “a” & “A” is different.
• Do • import • try
• In • void
Var, let & const
let: variable cannot be re-declared but can be updated. A block scope variable.
• Comparison operators : (==, !=, ===, !==, <, <=, >, >=)
str.length
str[0],str[1],str[2]
Template Literals
A way to have embedded expressions in strings
`this is a template literal`
• str.toUpperCase( )
• str.toLowerCase( )
• str.charAt( idx )
Practice Set 6
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.
Qs2. Write a JavaScript function that counts the number of vowels (a, e, i, o, u) in a
given string and returns the count. For example, if the input is "hello", the output
should be 2.
Qs3. Write a JavaScript program that takes a sentence as input and returns the
longest word in the sentence. For example, if the input is "The quick brown fox
jumps over the lazy dog", the output should be "jumps".
Loops
Loops are used to execute a piece of code again & again
while (condition) {
//do some work
}
Loops
do {
//do some work
} while (condition) ;
Loops
Collections of items
1 2 3 4 5
Looping over an Array
Print all elements of an array
Practice Set 9
Qs. For a given array with marks of students -> [85, 97, 44, 37, 76, 60]
Qs. For a given array with prices of 5 items -> [250, 645, 300, 900, 50]
All items have an offer of 10% OFF on them. Change the array to store
final price after applying offer.
Arrays
Use the reduce method to calculate sum of all numbers in the array.
Use the reduce method to calculate product of all numbers in the array.
The 3 Musketeers of Web Dev
HTML CSS JS
(Structure) (Style) (Logic)
Start The Code With Connectivity
document.getElementById(“myId”)
document.getElementsByClassName(“myClass”)
document.getElementsByTagName(“p”)
DOM Manipulation
• innerText : returns the text content of the element and all its children
• node.style
DOM Manipulation
let el = document.createElement(“div“)
Insert the button as the first element inside the body tag.
Now create a new class in CSS and try to append this class to the element.
Did you notice, how you overwrite the class name when you add a new one?
Example
btn.onclick = ( ) => {
console.log(“btn was clicked”);
}
Event Object
It is a special object that has details about the event.