Skip to content

Commit

Permalink
modified
Browse files Browse the repository at this point in the history
  • Loading branch information
Codetuber2024 committed Jun 27, 2024
1 parent cecd667 commit 12e44a2
Show file tree
Hide file tree
Showing 28 changed files with 792 additions and 49 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
14 changes: 14 additions & 0 deletions DOM/dynamicelementcreate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>dyamicelementcreateusingdom</title>
</head>
<body>
<button id="btn"> Click me</button>
<button id="btn1"> Click me</button>
<button id="btn2">Click me</button>
<script src="dynamicelementcreate.js"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions DOM/dynamicelementcreate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const btn= document.querySelector('#btn')
btn.addEventListener('click',()=>
{
const head1= document.createElement('h1')
head1.setAttribute('id','heading')
head1.innerHTML='this is heading'
document.body.appendChild(head1)

})
btn1.addEventListener('click',()=>
{
const ul= document.createElement('ul')
const li=document.createElement('li')
ul.setAttribute('id','unordered')
ul.appendChild(li)
li.innerText='added unordered list'
document.body.appendChild(ul)
})
let count=1
btn2.addEventListener('click',()=>
{
const li= document.createElement('li')
li.innerText=count;
document.body.appendChild(li)
count=count+2;
})
3 changes: 3 additions & 0 deletions DOM/eventlistener.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
<title>event listner</title>
</head>
<body>
<p class="color" id="redcolor">hi,i belong to coding community</p>
<button onclick="document.write('dont')">click me </button>
<button onclick="clickMe()" >click me </button>
<button id="btn">click me </button>
<button id="btn1">button is clicked</button>
<button id="red">redd</button>
<script src="eventlistener.js"></script>
</body>
</html>
30 changes: 29 additions & 1 deletion DOM/eventlistener.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,32 @@ function clickMe()
}
const btn= document.getElementById('btn')

btn.onclick=()=>document.write('clicked')
btn.onclick=()=>document.write('clicked')

const btn1=document.getElementById('btn1')
btn1.addEventListener('click',()=>
{
document.write('clickedbutton')
})

//red.addEventListener('click',()=>
//{
const redcolor= document.getElementById('redcolor')
//redcolor.style.color='red'
// redcolor.style.backgroundColor='yellow'
red.addEventListener('click',()=>{
if(redcolor.style.color==='red'){redcolor.style.color='blue'
}
else{
redcolor.style.color='red'
}
})



//})
const body= document.querySelector('body')
body.addEventListener('click',()=>
{
body.remove();
})
1 change: 1 addition & 0 deletions Generatorfunction/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Iterator Pattern Genearator Function #YIELD Keyword
19 changes: 19 additions & 0 deletions Generatorfunction/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//Built-in iterator
for(const val of [1,2,3,4,5]){
console.log(val)
}
//YIELD
function *create(){
console.log('how')
yield 'many';
console.log('coding')
yield 'community';
}
const cr=create()
/*console.log(cr.next().value)
console.log(cr.next().value)*/

for(let val of cr){
console.log(val)
}

110 changes: 110 additions & 0 deletions IIFE/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
(function add(a,b){console.log(a+b)})(2,3);

(function print(){console.log("hello")})();

(()=>console.log('hii'))();

const divide =((a,b)=> a/b)(4,2);
console.log(divide);


const value=(()=>100)();
console.log(value)

// Regular Function
function add(a,b){
console.log(a+b)
}
add(2,3)


// Arrow function
const a=()=>{
console.log(26)
}

// Regular IIFE
(function something(){
console.log('something but nothing')
})();

//Anonymous IIFE
(function Do(){
console.log('Arrow IIFE')
})();

//arrow IIFE
(arrow=()=>{
console.log('Arrow IIFE')
})();

let age=25;
arrow=(()=>{
age=27;
console.log(age+1);
})();


const val= ((a,b)=> a-b)(9,9);
console.log(val)
/*
const multiply =((a,b)=>{return a*b})
(3,2);
console.log(multiply);
*/
//atm
/*
const atm= function(startBal){
let bal= startBal;
function withdraw(amt){
if(amt>bal){
throw err;
}
else{
bal-=amt;
return bal;
}
}
return {withdraw};
};
const mahima= atm(2000)
console.log(mahima.withdraw(200))
*/


const x='xyz';
const hi=()=>"hii";
(()=>{
const x='lol';
const hi=()=>"hello";
console.log(x);
console.log(hi());
})();


// Private variable and methods from closure
const increment=(()=>{
let counter=0
console.log(counter)
const credits=(num)=>console.log(`I have ${num} credits `)
return ()=> {++counter; credits(counter);}
})();
increment()

// Module Pattern
const Score =(()=>{
let count=0
return {
current:()=>{return count},
increment:()=>{count ++},
reset:()=>{count=0}
}
})();
Score.increment()
console.log(Score.current())
Score.increment()
console.log(Score.current())
Score.reset()
console.log(Score.current())
14 changes: 14 additions & 0 deletions Promisification/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Promisifiication</title>
</head>
<body>
<h1>Promisification</h1>
<script src="index.js"></script>
<script src="test.js"></script>
</body>
</html>
17 changes: 17 additions & 0 deletions Promisification/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function loadScript(src,callback){// src--it will give script urland callback will give callback function
const script= document.createElement('script')
script.src=src;
script.onload=()=>callback(null,script)
script.onerror=(err)=>callback(err)
document.head.appendChild(script)


}
loadScript('test.js',(err,script)=>{
if(err){
console.log(err)
}
else{
console.log('script loaded')
}
})
1 change: 1 addition & 0 deletions Promisification/text.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('hello lolo')
57 changes: 57 additions & 0 deletions array/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const arr=[2,4,6,8,133]
const res = arr.forEach((item) => {
return item * item;
});

// it will return new array after performing operation
const ret= arr.map((val)=>{
return val *val
})
console.log(ret)
//console.log(typeof ret)

// array of object
const arrObj=[
{
name:'Raj',
age:22,
profession:'Mern Stack'
},
{
name:'kiara',
age:28,
profession:' Software Engineer'
},
{
name:'sheena',
age:30,
profession:'Frontend developer'
},
{
name:'Preeti',
age:30,
profession:'Frontend developer'
},
{
name:'Mayank',
age:37,
profession:'Frontend developer'
},
{
name:'ram',
age:70,
profession:'software developer'
},
]

const newArr= arrObj.filter((val)=>{
return val.profession=='Frontend developer';
})
console.log(newArr)


const red= arr.reduce((curr,total,index,array)=>{

return curr
})
console.log(red)
Empty file.
13 changes: 13 additions & 0 deletions closure/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>closure</title>
</head>
<body>
<h1 id="closure" style="font-size: 80px;">closure</h1>
<button id="btn">Click me</button>
<script src="index.js"></script>
</body>
</html>
Loading

0 comments on commit 12e44a2

Please sign in to comment.