Skip to content

Instantly share code, notes, and snippets.

@csandman
Created August 29, 2019 18:49
Show Gist options
  • Save csandman/c0e8daa113463643cc558bbaa438c538 to your computer and use it in GitHub Desktop.
Save csandman/c0e8daa113463643cc558bbaa438c538 to your computer and use it in GitHub Desktop.
Get a random dad joke from icanhazdadjoke.com
const getDadJoke = async () => {
const dadJoke = await fetch("https://icanhazdadjoke.com/", {
headers: {
Accept: "application/json"
}
});
const dadJokeJSON = await dadJoke.json();
if (dadJokeJSON.status === 200) {
return dadJokeJSON.joke;
} else {
return "Error retrieving dad joke!"
}
};
(async () => console.log(await getDadJoke()))();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment