-
-
Save ilearnjavascript/13bc1c87fa0cee1f195a042c997c37c5 to your computer and use it in GitHub Desktop.
es8 - async await - 1.js
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
async function getJoke() { | |
let url = 'https://api.icndb.com/jokes/random'; | |
let result = await (await fetch(url)).json(); | |
return result; | |
} | |
async function initApiCall() { | |
try { | |
let data = await getJoke(); | |
console.log(data.value.joke) | |
} | |
catch (err) { | |
console.error(`ERROR(${err.code}): ${err.message}`); | |
} | |
} | |
initApiCall(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment