-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6655 from nox456/main
Reto #10 - javascript
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
})() |