Skip to content

Instantly share code, notes, and snippets.

@Prasanna-Poonacha
Created November 2, 2020 11:03
Show Gist options
  • Save Prasanna-Poonacha/fc16effb0186220bd082cec609659fda to your computer and use it in GitHub Desktop.
Save Prasanna-Poonacha/fc16effb0186220bd082cec609659fda to your computer and use it in GitHub Desktop.
Callbacks
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Interview</title>
</head>
<body>
<script>
const posts = [
{ title: 'Post1', body: 'This is post one' },
{ title: 'Post2', body: 'This is post two' },
];
function createPost(post) {
setTimeout(function () {
posts.push(post);
}, 2000);
}
function getPosts() {
setTimeout(function () {
let output = '';
posts.forEach(function (post) {
output += `<li>${post.title}</li>`;
});
document.body.innerHTML = output;
}, 1000);
}
createPost({ title: 'Post3', body: 'This is post three' });
getPosts();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment