October 23, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { fetch } from "https://esm.town/v/std/fetch";
export const extractRandomCardImage = async () => {
try {
const response = await fetch(
"https://deckofcardsapi.com/api/deck/new/draw/?count=1"
);
const data = await response.json();
if (data.success && data.cards && data.cards.length > 0) {
const cardImage = data.cards[0].image;
return { data: cardImage };
} else {
throw new Error("No cards found in the response.");
}
} catch (error) {
console.log("Error fetching random card image:", error);
return {
data: `An error occurred while fetching the random card image. ${error}`,
};
}
};
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