-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathtest3.js
More file actions
44 lines (37 loc) · 1.16 KB
/
Copy pathtest3.js
File metadata and controls
44 lines (37 loc) · 1.16 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
function getTime() {
return new Date().toLocaleTimeString();
}
function fetchDataFromAPI(callback) {
console.log(`[${getTime()}] Fetching data from API...`);
setTimeout(() => {
const data = { id: 1, name: "Vraj", role: "Developer" };
console.log(`[${getTime()}] Data retrieved!`);
callback(data);
}, 2000);
}
function displayData(data) {
console.log(`[${getTime()}] Displaying Data:`, data);
}
fetchDataFromAPI(displayData);
function fetchUser(callback) {
console.log(`[${getTime()}] Starting user data fetch...`);
setTimeout(() => {
console.log(`[${getTime()}] User data fetched`);
callback({ userId: 101, username: "John Doe" });
}, 1000);
}
function fetchPosts(user, callback) {
console.log(`[${getTime()}] Fetching posts for ${user.username}...`);
setTimeout(() => {
console.log(`[${getTime()}] Posts fetched for ${user.username}`);
callback(["Post 1", "Post 2", "Post 3"]);
}, 3000);
}
function displayPosts(posts) {
console.log(`[${getTime()}] User Posts:`, posts);
}
fetchUser((user) => {
fetchPosts(user, (posts) => {
displayPosts(posts);
});
});