Skip to content

Commit ff468a6

Browse files
Failed to show the third post
1 parent f230a7e commit ff468a6

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

promises/app.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// const isLogin = true;
2+
// const promise = new Promise((res,rej)=>{
3+
// if(isLogin === true){
4+
// res("Logged In");
5+
// }
6+
// else{
7+
// rej("Not Logged In");
8+
// }
9+
// })
10+
// promise.then((mes)=>{
11+
// console.log(mes);
12+
// })
13+
// promise.catch(()=>{
14+
// console.log(mes);
15+
// })
16+
17+
18+
// const uri = "https://jsonplaceholder.typicode.com/posts"
19+
// const arrData = [];
20+
// const data = fetch(uri)
21+
22+
// data.then((res)=>res.json()).then((data)=>arrData.push(data))
23+
// data.catch((err)=>console.log(err))
24+
25+
// console.log(arrData)
26+
27+
28+
const posts = [
29+
{title:"Post one",body:"This is post one"},
30+
{title:"Post two",body:"This is post two"}
31+
]
32+
33+
function getPosts(){
34+
setTimeout(()=>{
35+
let output = "";
36+
posts.forEach((post,index)=>{
37+
output += `<li>${post.title}</li>`;
38+
});
39+
document.body.innerHTML = output
40+
},1000);
41+
}
42+
43+
function createPost(post){
44+
setTimeout(()=>{
45+
posts.push(post)
46+
},2000)
47+
}
48+
getPosts();
49+
createPost({title:"Post three",body:"This is post three"})

promises/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Promises</title>
7+
</head>
8+
<body>
9+
10+
<script src="./app.js"></script>
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)