xxxxxxxxxx
34
// Daniel Shiffman
// http://codingtra.in
// Promises Part 1
// Video: https://youtu.be/QO4NXhWo_NM
// To run this sketch, replace ADD_YOUR_KEY
// in the urls below, with your own API key.
// Giphy API: https://developers.giphy.com/
// Giphy API Tutorial: https://youtu.be/mj8_w11MvH8
// Wordnik API: https://developer.wordnik.com/
// Wordnik API Tutorial: https://youtu.be/YsgdUaOrFnQ
const wordnikAPI =
'https://api.wordnik.com/v4/words.json/randomWord?&minLength=5&maxLength=-1&api_key=ADD_YOUR_KEY';
const giphyAPI =
'https://api.giphy.com/v1/gifs/search?rating=PG&api_key=ADD_YOUR_KEY&q=';
function setup() {
noCanvas();
fetch(wordnikAPI)
.then(response => response.json())
.then(json => {
createP(json.word);
return fetch(giphyAPI + json.word);
})
.then(response => response.json())
.then(json => {
console.log(json)
createImg(json.data[0].images['fixed_height_small'].url);
})
.catch(err => console.log(err));
}