Skip to content

Commit

Permalink
Add files demoing fetch API and promises
Browse files Browse the repository at this point in the history
  • Loading branch information
mattry committed Dec 11, 2024
1 parent 1f095a0 commit 7ee35c1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions week1/day3/fetchdemo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let fetchRes = fetch("https://jsonplaceholder.typicode.com/posts/1");

fetchRes.then(res=>
res.json()).then(
data=>{
console.log(data)
}
).catch((error)=>{
console.log(error);
})
12 changes: 12 additions & 0 deletions week1/day3/promisedemo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const getSomething = () => {
return new Promise((resolve, reject) => {
//resolve("some data");
reject("some error");
})
}

getSomething().then(data=>{
console.log(data)
}).catch(err=>{
console.log(err)
})

0 comments on commit 7ee35c1

Please sign in to comment.