Skip to content

Commit

Permalink
Reto #10 - javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
nox456 committed Aug 21, 2024
1 parent 8e3fd50 commit 8b012f1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Retos/Reto #10 - LA API [Media]/javascript/nox456.js
Original file line number Diff line number Diff line change
@@ -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"))
})()

0 comments on commit 8b012f1

Please sign in to comment.