-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
60 lines (50 loc) · 1.23 KB
/
app.js
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
const btn1 = document.getElementById("btn-1");
const btn2 = document.getElementById("btn-2");
const btn3 = document.getElementById("btn-3");
const data1 = document.getElementById("data1");
const data2 = document.getElementById("data2");
const data3 = document.getElementById("data3");
// create object of data
let dell = {
brand: "Dell",
hardDisk: "2 TB",
color: "Black",
};
let hp = {
brand: "HP",
hardDisk: "1 TB",
color: "red",
};
let notAvailable = {
brand: "Not Available",
status: "failed",
};
let buyLaptop = new Promise((resolve, reject) => {
setTimeout(() => {
resolve(dell);
}, 5000);
});
// Call a function for btn action
function buttonAction() {
buyLaptop.then((res) => {
data1.innerText = JSON.stringify(res);
// console.log(res);
});
}
// example 02:
async function buttonAction2() {
data2.innerText = "loading Data ";
let data = await buyLaptop;
console.log(data);
data2.innerText = JSON.stringify(data);
}
// example 03:
// fetch Api
const api = fetch("https://jsonplaceholder.typicode.com/users")
.then(response => response.json())
function buttonAction3() {
data3.innerText = "Loading Data .....";
api.then(res => {
data3.innerText = JSON.stringify(res)
});
}