Created
November 2, 2020 11:03
-
-
Save Prasanna-Poonacha/fc16effb0186220bd082cec609659fda to your computer and use it in GitHub Desktop.
Callbacks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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