Random Giphy

Get random gif using async and await.

by Rodwyn Moreno

JavaScript

const getImagen = async () => {
	try {
  	const apiKey = 'swbFspRTjwsaFOAtITNuUWGQ0AQGOedH';
    const response = await fetch(`https://api.giphy.com/v1/gifs/random?api_key=${apiKey}`);
    const { data } = await response.json();
    const { url } = data.images.original;
    const img = document.createElement('img');
    
    img.src = url;
    document.body.append(img);
  }
  catch(error) {
  	console.error(error);
  }
};

getImagen();