diff --git a/Apirequest.html b/Apirequest.html new file mode 100644 index 0000000..fe0278b --- /dev/null +++ b/Apirequest.html @@ -0,0 +1,34 @@ + + + + + + Document + + + 0 UNSENT Client has been created. open() not called yet. +1 OPENED open() has been called. +2 HEADERS_RECEIVED send() has been called, and headers and status are available. +3 LOADING Downloading; responseText holds partial data. +4 DONE The operation is complete. + + + + + \ No newline at end of file diff --git a/call.js b/call.js new file mode 100644 index 0000000..30e837c --- /dev/null +++ b/call.js @@ -0,0 +1,14 @@ +function SetUserName(username){ + //complex DB calls + this.username = username +} + +function createUser(username,email,password){ + + SetUserName.call(this,username) + + this.email = email + this.password = password +} +const chai = new createUser("chai","gauri@jknd.com","12345") +console.log(chai); diff --git a/classes.js b/classes.js new file mode 100644 index 0000000..30a13e6 --- /dev/null +++ b/classes.js @@ -0,0 +1,35 @@ +//ES6 + +// class User{ +// constructor(username,email,password){ +// this.username = username; +// this.email = email; +// this.password = password +// } + +// encryptPassword(){ +// return `${this.password}abc` +// } +// changeUserName(){ +// return `${this.username.toUpperCase()}` +// } +// } +// const chai = new User("gauri","njndjn@nkjn.com","123") +// console.log(chai.encryptPassword()); +// console.log(chai.changeUserName()); + +//behind the scene +function User(username,email,password){ + this.username = username; + this.email = email; + this.password = password +} +User.prototype.encryptPassword = function(){ + return`${this.password}abc` +} +User.prototype.changeUserName = function(){ + return`${this.password}abc` +} +const tea = new User("tea","njhgyddn.com","123") +console.log(tea.encryptPassword()); +console.log(tea.changeUserName()); diff --git a/five.js b/five.js new file mode 100644 index 0000000..5de0e28 --- /dev/null +++ b/five.js @@ -0,0 +1,41 @@ +// const coding = ["js","ruby","java","python","cpp"] +// const values = coding.forEach((item)=>{ +// console.log(item); + + +// }) + +// console.log(values); + + const myNums = [1,2,3,4,5,6,7,8,9] +// const newNums = myNums.filter((num)=>{ +// return num>4; +// }) +// console.log(newNums); + +const newNums = [] +myNums.forEach((num)=>{ + if(num>2){ + newNums.push(num) + } +}) +//console.log(newNums); + +const books = [ + {title:'book one',genre:'fiction',publish:1981, + edition:2004 }, + {title:'book two',genre:'Non-fiction',publish:1992, + edition:2008 }, + {title:'book three',genre:'History',publish:1999, + edition:2007}, + {title:'book four',genre:'spiritual',publish:1989, + edition:2010 }, + {title:'book five',genre:'self help',publish:2009, + edition:2014 }, + {title:'book six',genre:'History',publish:1987, + edition:2010 }, + {title:'book seven',genre:'motivational',publish:1986, + edition:1996 }, +]; +const userBooks = books.filter((bk)=>bk.publish > 2000) +console.log(userBooks); diff --git a/four.html b/four.html new file mode 100644 index 0000000..d3f614e --- /dev/null +++ b/four.html @@ -0,0 +1,42 @@ + + + + + + DOM with chai aur code + + + + + + \ No newline at end of file diff --git a/four.js b/four.js new file mode 100644 index 0000000..025a014 --- /dev/null +++ b/four.js @@ -0,0 +1,32 @@ +//for in +const myObject = { + js:'javascript', + cpp:'c++', + rb:'ruby', + swift:'swift by apple' + +} +for (const key in myObject) { + console.log(myObject[key]); + +} +//for each + +const myCoding = [ + { + languageName:"Javascript", + fileName:"js" + }, + { + languageName:"C++", + fileName:"Cpp" + }, + { + languageName:"python", + fileName:"py" + } +] +myCoding.forEach((item)=>{ + + console.log(item.languageName); +}) diff --git a/getter_setter.js b/getter_setter.js new file mode 100644 index 0000000..004f1f3 --- /dev/null +++ b/getter_setter.js @@ -0,0 +1,21 @@ +class User { + constructor(email,password){ + this.email = email; + this.password = password + } + + get email(){ + return this._email.toUpperCase() + } + set email(value){ + this._email = value + } + get password(){ + return this._password.toUpperCase() + } + set password(value){ + this._password = value + } +} +const gauri = new User("gauri@1.ai","123") +console.log(gauri.password); \ No newline at end of file diff --git a/inheritance.js b/inheritance.js new file mode 100644 index 0000000..5c50530 --- /dev/null +++ b/inheritance.js @@ -0,0 +1,22 @@ +class User { + constructor(username){ + this.username = username + } + logMe() { + console.log(`USERNAME is ${this.username}`); + } +} + +class Teacher extends User{ + constructor(username,email,password){ + super(username) + this.email = email; + this.password = password + } + + addCourse(){ + console.log(`new course was added by ${this.username}`); + } +} +const chai = new Teacher("chai","chaicode@goo.com","123") +chai.addCourse() \ No newline at end of file diff --git a/mathpi.js b/mathpi.js new file mode 100644 index 0000000..f19765d --- /dev/null +++ b/mathpi.js @@ -0,0 +1,16 @@ +// const descriptor = Object.getOwnPropertyDescriptor(Math,"PI") + +// console.log(descriptor); + +const chai ={ + name:"ginger chai", + price:250, + isAvailable:true +} +console.log(Object.getOwnPropertyDescriptor(chai,"name")); + +Object.defineProperty(chai,'name',{ + writable:false, + enumerable:false +}) +console.log(Object.getOwnPropertyDescriptor(chai,"name")); \ No newline at end of file diff --git a/nodes.md b/nodes.md new file mode 100644 index 0000000..63f9e1a --- /dev/null +++ b/nodes.md @@ -0,0 +1,24 @@ +# Javascript and classes +# OOP + + +# object +-collection of properties and methods +-toLowerCase +-toUpperCase + +## why use OOP +# parts of OOP +Object literal + +-Constructor function +-Prototypes +-Classes +Instances(new,this) + + +# 4 pillars +Abstraction +Encapsulation +Inheritance +Polymorphism \ No newline at end of file diff --git a/object.js b/object.js new file mode 100644 index 0000000..0799cd1 --- /dev/null +++ b/object.js @@ -0,0 +1,21 @@ +function multiplyBy5(num){ + return num*5; +} +multiplyBy5.power = 2 +console.log(multiplyBy5(5)); +console.log(multiplyBy5.power); +console.log(multiplyBy5.prototype); + +function createUser(username,score){ + this.username = username + this.score = score +} +createUser.prototype.increment = function(){ + this.score++ +} +createUser.prototype.printMe = function(){ + console.log(`score is ${this.score}`); +} +const chai = new createUser("Chai",25) +const tea = new createUser("tea",50) +chai.printMe() diff --git a/one.html b/one.html new file mode 100644 index 0000000..cb2aebc --- /dev/null +++ b/one.html @@ -0,0 +1,61 @@ + + + + + + HTML Events + + +

Amazing images

+
+ +
+ + + \ No newline at end of file diff --git a/one.js b/one.js new file mode 100644 index 0000000..f311c63 --- /dev/null +++ b/one.js @@ -0,0 +1,22 @@ +for (let i = 0; i < 10; i++) { + const element = i; + //console.log(element); + +} +for (let i = 0; i <=10 ; i++) { + // console.log(`Outer loop value:${i}`); + + for (let j = 0; j <= 10 ; j++) { + // console.log(i +'*'+ j + '=' +i*j); + + } + +} + +let myArray = ["flash", "batman","superman"] +for (let index = 0; index < myArray.length; index++) { + const element = myArray[index]; + //console.log(element); + +} + diff --git a/oop.js b/oop.js new file mode 100644 index 0000000..e4d8b72 --- /dev/null +++ b/oop.js @@ -0,0 +1,35 @@ +// const user = { +// username:"Gauri", +// loginCount:8, +// signedIn:true, +// getUserDetails: function(){ +// //console.log("Got user details from database"); +// //console.log(`username ${this.username}`); +// } + +// } +//console.log(user.username); +//console.log(user.getUserDetails()); + +//const promise = new Promise() +//const date = new Date() + +function User(username,loginCount,isLoggedIn){ + this.username = username; + this.loginCount = loginCount; + this.isLoggedIn = isLoggedIn; + + this.greeting = function(){ + console.log(`welcome ${this.username}`); + } + + //return this +} + +const userOne = new User("Gauri",12,true) +const userTwo = new User("Js",20,true) +console.log(userOne); +//new keyword creates an new object +//after new keyword a constructor function is called +//arguments inject in this keyword + diff --git a/promise.js b/promise.js new file mode 100644 index 0000000..993d821 --- /dev/null +++ b/promise.js @@ -0,0 +1,83 @@ +const promiseOne = new Promise(function(resolve, reject){ + //Do an async task + //DB calls,cryptography,network + setTimeout(function() { + console.log('async task is complete'); + resolve() + }, 1000); +}) +promiseOne.then(function(){ + console.log('promise consumed'); +}) + +new Promise(function(resolve,reject){ + setTimeout(function(){ + console.log("Async task two"); + resolve() + }) +}).then(function(){ + console.log("Async two resolved"); +}) + +const promiseThree = new Promise(function(resolve,reject){ + setTimeout(function(){ + resolve({username:"chai" , email:'chai@example.com'}) + },1000) +}) +promiseThree.then(function (user) { + console.log(user); +}) + +promiseFour = new Promise(function(resolve,reject){ + setTimeout(function(){ + let error = true + if(!error){ + resolve({username: "Gauri", password: "123"}) + }else{ + reject('Error:Something went wrong') + } + },1000) +}) +promiseFour +.then((user)=>{ + console.log(user); + return user.username +}) +.then((username) =>{ + console.log(username); +} ) +.catch(function(error){ + console.log(error); +}) +.finally(()=> console.log("The promise is either resolved or rejected")); + + +const promiseFive = new Promise(function(resolve,reject){ + setTimeout(function(){ + let error = true + if(!error){ + resolve({username: "Javascript", password: "123"}) + }else{ + reject('Error:JS went wrong') + } + },1000) +}) + +async function consumePromiseFive(){ + try { + const response = await promiseFive + console.log(promiseFive); + } catch (error) { + console.log(error); + } +} +consumePromiseFive() + +fetch('https://api.github.com/users/gaurisonawane07') +.then((response)=>{ + return response.json() +}) +.then((data)=>{ + console.log(data); +}) +.catch((error) => console.log(error)); \ No newline at end of file diff --git a/prototype.js b/prototype.js new file mode 100644 index 0000000..aaffe87 --- /dev/null +++ b/prototype.js @@ -0,0 +1,52 @@ +// let myName = "Gauri " +// console.log(myName.truelength); + +let myHeroes = ["thor","spiderman"] +let heroPower = { + thor:"Hammer", + spiderman:"sling", + getSpiderPower: function(){ + // console.log(`Spider powes is ${this.spiderman}`); + } +} + +Object.prototype.gauri = function(){ + // console.log(`gauri is present in all objects`); +} + +Array.prototype.heyGauri = function(){ + // console.log(`Gauri says hello`); +} +// myHeroes.gauri() +// myHeroes.heyGauri() + +//heroPower.gauri() + +//****************************INHERITANCE*********************************/ +const User ={ + name:"chai", + email:"hbgdsdx@google.com" +} +const Teacher = { + makeVideo :true +} +const teachingSupport = { + isAvailable: false +} +const TASupport = { + makeAssignment: "JS assignment", + fullTime: true, + __proto__:teachingSupport +} +Teacher.__proto__ = User + +//modern syntax +Object.setPrototypeOf(teachingSupport,Teacher) + +let anotherUserName = "chaiAurCode " + +String.prototype.trueLength = function(){ + console.log(`${this}`); + console.log(`true length is ${this.trim().length}`); +} +anotherUserName.trueLength() \ No newline at end of file diff --git a/seven.js b/seven.js new file mode 100644 index 0000000..bbfb10e --- /dev/null +++ b/seven.js @@ -0,0 +1,7 @@ +//reduce +const myNums = [1,2,3] +const myTotal = myNums.reduce(function(acc,curVal){ + console.log(`accumulator is ${acc} + current value is ${curVal}`); + return acc + curVal +},0) +console.log(myTotal); \ No newline at end of file diff --git a/six.js b/six.js new file mode 100644 index 0000000..0d4526b --- /dev/null +++ b/six.js @@ -0,0 +1,9 @@ +//map +const myNums = [1,2,3,4,5,6,7,8,9,0] + +//const newNums = myNums.map((num)=> num+10) +//console.log(newNums); +const newNums = myNums + .map((num)=>num*10) + .map((num)=> num+1) +console.log(newNums); diff --git a/switch.js b/switch.js new file mode 100644 index 0000000..f9a24f4 --- /dev/null +++ b/switch.js @@ -0,0 +1,24 @@ +// switch (key) { +// case value: + +// break; + +// default: +// break; +// } +const month = 3 +switch (month) { + case 1: + console.log("january"); + break; + case 2: + console.log("Feb"); + break; + case 3: + console.log("March"); + break; + + default: + console.log("default case match"); + break; +} \ No newline at end of file diff --git a/three.html b/three.html new file mode 100644 index 0000000..aee5344 --- /dev/null +++ b/three.html @@ -0,0 +1,21 @@ + + + + + + Document + + +

Chai aur JAVASCRIPT

+ + + + + + \ No newline at end of file diff --git a/three.js b/three.js new file mode 100644 index 0000000..72156e5 --- /dev/null +++ b/three.js @@ -0,0 +1,23 @@ +//for of loop + +const arr = [1,2,3,4,5] + +for (const num of arr) { + console.log(num); +} + +const greeting = "Hello World!" +for (const greet of greeting) { + console.log(`Each char is ${greet}`); + +} + +//Maps +const map = new Map() +map.set('IN',"INDIA") +map.set('USA',"UNITED STATES OF AMERICA") +map.set('FR',"FRANCE") +console.log(map); +for (const [key,value] of map) { + console.log(key,"->",value); +} \ No newline at end of file diff --git a/truthy.js b/truthy.js new file mode 100644 index 0000000..11c9488 --- /dev/null +++ b/truthy.js @@ -0,0 +1,21 @@ +//falsy values +//false,0,-0,BigInt 0n,"",null,undefined,NaN + +//truthy values +//"0",'false'," ",[],{},function(){} +const userEmail = "gauri@03"; +if(userEmail.length === 0){ + console.log("Array is empty"); +} + +//nullish coalscing Operator(??):null undefined +let val1; +val1 = 5 ?? 10 +console.log(val1); +let val2 = null ?? 10; +console.log(val2); + +//terniary operator + +const iceTeaPrice = 100 +iceTeaPrice>= 80 ? console.log("Less Than 80"):console.log("More then 80"); \ No newline at end of file diff --git a/two.html b/two.html new file mode 100644 index 0000000..1803e02 --- /dev/null +++ b/two.html @@ -0,0 +1,29 @@ + + + + + + Document + + +

Chai aur code

+ + + + + \ No newline at end of file diff --git a/two.js b/two.js new file mode 100644 index 0000000..b93f58e --- /dev/null +++ b/two.js @@ -0,0 +1,13 @@ +let index = 0 + +while (index <= 10) { + console.log(`value of index is ${index}`); + index = index + 2 +} + + +let score = 11 +do { + console.log(`Score is ${score}`); + +} while (score<=10);