diff --git a/Retos/Reto #10 - LA API [Media]/javascript/nox456.js b/Retos/Reto #10 - LA API [Media]/javascript/nox456.js new file mode 100644 index 0000000000..caaffc3928 --- /dev/null +++ b/Retos/Reto #10 - LA API [Media]/javascript/nox456.js @@ -0,0 +1,27 @@ +// The Legend Of Zelda API (https://docs.zelda.fanapis.com/) +const BASE_URL = "https://zelda.fanapis.com/api" + +async function getGames(name) { + const gamesUrl = `${BASE_URL}/games` + let data + if (name) { + try { + const res = await fetch(`${gamesUrl}?name=${name}`) + data = await res.json() + } catch(e) { + return e + } + } else { + try { + const res = await fetch(gamesUrl) + data = await res.json() + } catch(e) { + return e + } + } + return data +} + +(async () => { + console.log(await getGames("Ocarina")) +})()