-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
33 lines (29 loc) · 748 Bytes
/
Copy pathapp.js
File metadata and controls
33 lines (29 loc) · 748 Bytes
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
let posts = [{
"title": "title 1",
"body": "body 1"
},
{
"title": "title 2",
"body": "body 2"
}
]
function addPost(callback /*callback function*/ ) {
setTimeout(function () {
posts.push({
"title": "title 3",
"body": "body 3"
})
callback(); // callback function
}, 3000);
}
function getAllPosts() {
setTimeout(function () {
let output = "<ul>";
posts.forEach(function (post) {
output += `<li>${post.title} - ${post.body}</li>`;
})
output += "</ul>";
document.getElementById('output').innerHTML = output;
}, 2000);
}
addPost(getAllPosts); // to make it sync and it will run after 5 sec.