diff --git a/Assignment_js/Apis.js b/Assignment_js/Apis.js index 02329eb0..2534cb1d 100644 --- a/Assignment_js/Apis.js +++ b/Assignment_js/Apis.js @@ -31,5 +31,32 @@ function handleResponse(error, data) { fetchData(handleResponse); //promises +function fetchApi(){ + let url = 'https://jsonplaceholder.typicode.com/todos/1' + console.log("fetching api 1.....") + return new Promise((resolve)=>{ + setTimeout(() => { + fetch('https://jsonplaceholder.typicode.com/todos/1') + .then((url)=>url.json()) + .then((url)=>console.log(url.json)) + resolve("resolve successfull...") + resolve(); + }, 3000); + }) +} + +function fetchApi1(){ + let url = 'https://jsonplaceholder.typicode.com/todos/2' + console.log("fetching api 2.....") + return new Promise((resolve)=>{ + setTimeout(() => { + fetch('https://jsonplaceholder.typicode.com/todos/2') + .then((url)=>url.json()) + .then((url)=>console.log(url.json)) + resolve("resolve successfull...") + resolve(); + }, 3000); + }) +} diff --git a/DumyFile.js b/DumyFile.js new file mode 100644 index 00000000..2d7fadba --- /dev/null +++ b/DumyFile.js @@ -0,0 +1,103 @@ +function fetchApi1(){ + let url = 'https://jsonplaceholder.typicode.com/todos/2' + console.log("fetching api 2.....") + return new Promise((resolve)=>{ + setTimeout(() => { + fetch('https://jsonplaceholder.typicode.com/todos/2') + .then((url)=>url.json()) + .then((url)=>console.log(url.json)) + resolve("resolve successfull...") + resolve(); + }, 3000); + }) +} + +async function All(){ + await fetchApi(); + await fetchApi1(); +} + +//First array in we can change values and add attributes +var arr1 = [22, + true, + "Hello", + obj={ + name : "Kashan",age: 34,cgpa:3.5, +}] +console.log(arr1); +// Add a new property to the object inside the array +arr1[3].grade = 'A'; +console.log(arr1); +//change value of name +arr1[3].name = "ALI" +console.log(arr1) +arr1.push("New value") +console.log(arr1) + +//Example 2 + +function func2(...num) { + let sum = 0; // Initialize sum outside the loop + + for (let i = 0; i < num.length; i++) { + sum = sum + num[i]; // Update sum with each element + } + + console.log(sum); +} + +func2(1, 2, 3, 4, 5); + +//function which print even number +console.log("***************************************"); + +function fun2 (y){ + for(let i=0;i<=y;i++){ + if(i%2==0){ + console.log(i); + } + } + +} +fun2(20); + + +//Destructring + +let arr = [1,2,3,4,5]; +let [a,b,...rest] = arr; +console.log(a); +console.log(b); +console.log(rest); +console.log(...arr); + +let student = {//This is an object variable which store key value pair. + name : "Muhammad Nadeem", + fatherName : "AbluHassan", + age : 22, + city : "skardu", + institution : "NetBots", +} +console.log("Hello my name is " + student.name + " my father Name is " + student.fatherName + " and i am " + student.age + " year old. "); + +let num = 5; +console.log(num); +++num; +console.log(++num); //increment before exicution +console.log(num++);//increment after exicution exicution +console.log(num) + +console.log("**************************************************"); +//var variable can be reinitialize and can be modify +var name = "Muhammad"; +console.log(name); +//errow function + +const fun2 = ((y)=>{ + for(let j = 0; j<=y; j++){ + if(j%2==0){ + console.log("Even numbers are : ","\t",j); + } + } +}) +fun2(10); //function call \ No newline at end of file diff --git a/fetchApi.js b/fetchApi.js new file mode 100644 index 00000000..d87a72d8 --- /dev/null +++ b/fetchApi.js @@ -0,0 +1,118 @@ + +//callback function + +// function FetchingApi1(callback) { +// console.log("Fetching data 1 ........."); +// fetch('https://jsonplaceholder.typicode.com/todos/1') +// .then((res)=>res.json()) +// .then((res)=>console.log(res.json)) +// setTimeout(() => { +// console.log("Data 1 fetched : ") +// callback(); +// }, 2000); +// } + +// function FetchingApi2(callback) { +// console.log("Fetching data 2 ........."); +// fetch('https://jsonplaceholder.typicode.com/todos/2') +// .then((res)=>res.json()) +// .then((res)=>console.log(res.json)) +// setTimeout(() => { +// console.log("Data 2 fetched : ") +// callback(); +// }, 2000); +// } + +// function FetchingApi3(callback) { +// console.log("Fetching data 3 ........."); +// fetch('https://jsonplaceholder.typicode.com/todos/3') +// .then((res)=>res.json()) +// .then((res)=>console.log(res.json)) +// setTimeout(() => { +// console.log("Data 3 fetched : ") +// callback(); +// }, 2000); +// } + +// FetchingApi1(()=>{ +// FetchingApi2(()=>{ +// FetchingApi3(()=>{ +// console.log("All done") +// }) +// }) +// }); + + +// promises function + +// function fetchApi(){ +// let url = 'https://jsonplaceholder.typicode.com/todos/1' +// console.log("fetching api 1.....") +// return new Promise((resolve)=>{ +// setTimeout(() => { +// fetch('https://jsonplaceholder.typicode.com/todos/1') +// .then((url)=>url.json()) +// .then((url)=>console.log(url.json)) +// resolve("resolve successfull...") +// resolve(); +// }, 3000); +// }) +// } + +// function fetchApi1(){ +// let url = 'https://jsonplaceholder.typicode.com/todos/2' +// console.log("fetching api 2.....") +// return new Promise((resolve)=>{ +// setTimeout(() => { +// fetch('https://jsonplaceholder.typicode.com/todos/2') +// .then((url)=>url.json()) +// .then((url)=>console.log(url.json)) +// resolve("resolve successfull...") +// resolve(); +// }, 3000); +// }) +// } + +// fetchApi(()=>{ +// fetchApi1(()=>{ + +// }) + +// }) + +//async await + + +function fetchApi(){ + let url = 'https://jsonplaceholder.typicode.com/todos/1' + console.log("fetching api 1.....") + return new Promise((resolve)=>{ + setTimeout(() => { + fetch('https://jsonplaceholder.typicode.com/todos/1') + .then((url)=>url.json()) + .then((url)=>console.log(url.json)) + resolve("resolve successfull...") + resolve(); + }, 3000); + }) +} + +function fetchApi1(){ + let url = 'https://jsonplaceholder.typicode.com/todos/2' + console.log("fetching api 2.....") + return new Promise((resolve)=>{ + setTimeout(() => { + fetch('https://jsonplaceholder.typicode.com/todos/2') + .then((url)=>url.json()) + .then((url)=>console.log(url.json)) + resolve("resolve successfull...") + resolve(); + }, 3000); + }) +} + +async function All(){ + await fetchApi(); + await fetchApi1(); +} + diff --git a/images/download.jfif b/images/download.jfif new file mode 100644 index 00000000..22abbb08 Binary files /dev/null and b/images/download.jfif differ