-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractise.html
More file actions
276 lines (262 loc) · 8.09 KB
/
practise.html
File metadata and controls
276 lines (262 loc) · 8.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
// let a = [10,20,30]
// let arr = a.map((value) => {
// console.log(value)
// return value + 1
// })
// console.log(arr)
//######################################## Chapter - 9
//Synchronous programming
// let a = prompt("What is your name:")
// let b = prompt("What is your dreamwork:")
// let c = prompt("What is your Ideal:")
// console.log("My name is " + a + ". & My Favourite Ideal is " + c + ". My DreamWork is " + b )
//Asynchronous programming
// console.log("START")
// setTimeout(function(){
// console.log("Hii This is My site");
// },3000)
// console.log("END");
//CALL BACKS
// document.addEventListener("DOMContentLoaded", function () {
// function loadScript(src, callback) {
// var script = document.createElement("script");
// script.src = src;
// script.onload = function () {
// console.log("Loaded script with SRC: " + src);
// callback(null, src);
// }
// script.onerror = function () {
// console.log("Error loading script with SRC: " + src);
// callback(new Error("Src got some error "))
// }
// document.body.appendChild(script);
// }
// function hello(error, src) {
// if(error){
// console.log(error)
// return
// }
// alert('Hii! Hello ' + src);
// }
// function good(error, src) {
// if(error){
// console.log(error)
// sendEmergencyMessageToCeo();
// return
// }
// alert("Good Morning.." + src);
// }
// loadScript("https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js", good);
// });
//Promises......
// let promise = new Promise(function(resolve,reject) {
// // alert("I am a alert in promise")
// alert("Hello")
// resolve(56)
// })
// console.log("Hello!!How Are You?");
// setTimeout(function(){
// console.log("Hello!! Hii, I am not good ")
// },2000)
// console.log("My name is " + "Hello ....")
// console.log(promise)
//fetch google.com homepage ==> console.log("google.com homepage done")
//fetch data from the data api
//fetch pictures from the server
//print downloading
//Rest of the script
//.then() and .catch()
// let p = new Promise((resolve, reject)=>{
// setTimeout(()=>{
// console.log("I am a promise and I am rejected")
// // resolve(true)
// reject(new Error("I am a error"))
// }, 5000)
// })
// console.log(p)
// let p1 = new Promise((resolve, reject)=>{
// console.log("Promise is pending")
// setTimeout(()=>{
// console.log("I am a promise and I am resolved")
// resolve(true)
// }, 5000)
// })
// let p2 = new Promise((resolve, reject)=>{
// console.log("Promise is pending")
// setTimeout(()=>{
// console.log("I am a promise and I am rejected")
// reject(new Error("I am a error"))
// }, 5000)
// })
// To get the value
// p1.then((value) => {
// console.log(value)
// })
//To catch the error
// p2.catch((error)=>{
// console.log("Some Error Occurred in p2");
// })
// p2.then((value) => {
// console.log(value)
// },(error)=>{
// console.log(error)
// })
// console.log(p1,p2);
//promise chaining .then() calls
// let p1 = new Promise((resolve, reject) => {
// setTimeout(() => {
// console.log("Resolved after 2 seconds")
// resolve(56)
// }, 2000)
// })
// p1.then((value) => {
// console.log(value)
// return p2 = new Promise((resolve, reject) => {
// setTimeout(() => { resolve("Promise 2") }, 2000)
// })
// // return p2
// }).then((value) => {
// console.log("We are Done.");
// return 2
// }).then((value) => {
// console.log("Now Done.")
// })
// const loadScript = (src) => {
// return new Promise((resolve, reject) => {
// const addScript = () => {
// let script = document.createElement("script");
// script.type = "text/javascript";
// script.src = src;
// document.body.appendChild(script);
// script.onload = () => resolve(1);
// script.onerror = () => reject(0);
// };
// Ensure document.body is available before appending
// if (!document.body) {
// document.addEventListener("DOMContentLoaded", addScript);
// } else {
// addScript();
// }
// });
// };
// let p1 = loadScript("https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js");
// p1.then((value) => {
// console.log("Script loaded successfully:", value);
// }).catch((err) => {
// console.error("Script failed to load", err);
// });
// let p1 = new Promise((resolve, reject) => {
// alert("Hey I am resolved")
// setTimeout(() => {
// resolve(1);
// }, 2000)
// })
// p1.then(() =>{
// // console.log("Congratrulations this promise is resolved");
// console.log("Hii, I am not good")
// return new Promise((resolve, reject) => {
// setTimeout(() => {
// resolve(4)
// }, 4000)
// })
// }).then((value) => { console.log(value)})
// p1.then(()=>{
// console.log("Mansi")
// })
//Promise Api
// let p1 = new Promise((resolve,reject) => {
// setTimeout(() => {
// resolve("value 1");
// }, 12000);
// });
// let p2 = new Promise((resolve,reject) => {
// setTimeout(() => {
// // resolve("value 2");
// reject(new Error("Error"));
// }, 2000);
// });
// let p3 = new Promise((resolve,reject) => {
// setTimeout(() => {
// resolve("value 3");
// }, 3000);
// });
// p1.then((value) => {
// console.log(value);
// });
// p2.then((value) => {
// console.log(value);
// });
// p3.then((value) => {
// console.log(value);
// });
// let promise_all = Promise.all([p1,p2,p3])
// let promise_all = Promise.allSettled([p1,p2,p3])
// let promise_all = Promise.race([p1,p2,p3])
// let promise_all = Promise.any([p1,p2,p3])
// let promise_all = Promise.resolve(6)
// let promise_all = Promise.reject(new Error("Hey , I am not good .."))
// promise_all.then((value) => {
// console.log(value)
// })
//Async/await
// async function Mansi() {
// let suratweather = new Promise((resolve, reject) => {
// setTimeout(()=> {
// resolve("30 degree")
// }, 2000)
// })
// let goaWeather = new Promise((resolve, reject) => {
// setTimeout(() => {
// resolve("21 degree")
// }, 7000)
// })
// suratweather.then(alert)
// goaWeather.then(alert)
// console.log("Fetching surat whether please wait....");
// let suratW = await suratweather
// console.log("Fetching surat whether:" + suratW);
// console.log("Fetching goa whether please wait.....");
// let goaW = await goaWeather
// console.log("Fetching goa whether:" + goaW);
// return [suratW, goaW]
// }
// const body = async () => {
// console.log("Hii, I am not good nowadays but still try smile..");
// }
// const main = async () => {
// console.log("Hello I am not good mood curently..")
// let a = await Mansi()
// let b = await body()
// // a.then((value) => {
// // console.log(value)
// // })
// }
// main()
//Error Handling : then() and catch() - only on script ne atke nai e mate help kare try catch
setTimeout(() => {
console.log("Hello please easy way to understaning...")
} , 1000)
try{
console.log(Mansi)
}
catch(error){
console.log("Whay always me in every time is my bad time..." + error)
}
setTimeout(() => {
console.log("Hello please easy way to understaning...")
} , 2000)
setTimeout(() => {
console.log("Hello please easy way to understaning...")
} , 3000)
</script>
</head>
<body>
</body>
</html>