Public
Script
1
2
3
4
5
6
7
8
9
10
11
import { fetch } from "https://esm.town/v/std/fetch";
export let fetchABird = async () => {
const MAX_ID = 777905;
const baseUrl = "https://xeno-canto.org/api/2/recordings";
const minAnimalId = Math.floor(Math.random() * (MAX_ID + 10));
const query = `?query=nr:${minAnimalId}-${minAnimalId + 10}`;
const response = await fetch(`${baseUrl}${query}`);
const json = await response.json();
return json.recordings[Math.floor(Math.random() * 9)];
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023