From 8486a7f75d97a9775f421b5450f21e00ed9d3621 Mon Sep 17 00:00:00 2001 From: jmedinac1987 Date: Mon, 6 Mar 2023 19:26:38 -0500 Subject: [PATCH] Reto #10 - JavaScript --- .../javascript/jmedinac1987.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Retos/Reto #10 - LA API [Media]/javascript/jmedinac1987.js diff --git a/Retos/Reto #10 - LA API [Media]/javascript/jmedinac1987.js b/Retos/Reto #10 - LA API [Media]/javascript/jmedinac1987.js new file mode 100644 index 0000000000..3843f700b4 --- /dev/null +++ b/Retos/Reto #10 - LA API [Media]/javascript/jmedinac1987.js @@ -0,0 +1,18 @@ +//Note: To run the following code in the Node.js console you must first install node-fetch with the following command 'npm install node-fetch' +import fetch from "node-fetch"; + +async function getWaifu(isNsfw) { + try { + let response = await fetch(`https://api.waifu.im/search?is_nsfw=${isNsfw}`); + let waifus = await response.json(); + + return waifus; + } catch (error) { + return error; + } +} + +let waifu = await getWaifu(false);//for children under 18 years of age +let waifuX = await getWaifu(true);//for over 18 years +console.log(waifu); +console.log(waifuX); \ No newline at end of file