diff --git a/assignment2/ques1.js b/assignment2/ques1.js new file mode 100644 index 0000000..778e1d9 --- /dev/null +++ b/assignment2/ques1.js @@ -0,0 +1,12 @@ +const func = async ()=>{ + console.log("Printing before") + await new Promise((resolve)=>{ + setTimeout(()=>{ + console.log("after waiting for 5 seconds") + resolve() + },5000) + }) + console.log("printing after") +} + +func(); \ No newline at end of file diff --git a/assignment2/ques2.js b/assignment2/ques2.js new file mode 100644 index 0000000..a8fa113 --- /dev/null +++ b/assignment2/ques2.js @@ -0,0 +1,21 @@ +// answer using promise. +const promise1=fetch("https://reqres.in/api/users") + +promise1.then((data)=>{ + console.log(data) +}).catch((error)=>{ + console.error("error occured",error) +}) + +//answer using async await function. +async function fetchData(){ + try{ + const data= await fetch("https://reqres.in/api/users") + console.log(data) + }catch(error){ + console.error("error occured : ",error.message) + } + +} + +fetchData(); \ No newline at end of file